1diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S 2index 3cd7e76cc562..2a08002ea765 100644 3--- a/arch/arm64/kernel/vmlinux.lds.S 4+++ b/arch/arm64/kernel/vmlinux.lds.S 5@@ -260,6 +260,15 @@ SECTIONS 6 INIT_RAM_FS 7 *(.init.altinstructions .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 efb66e25fa2d..c03c41f408cb 100644 23--- a/drivers/Kconfig 24+++ b/drivers/Kconfig 25@@ -235,6 +235,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/peci/Kconfig" 34diff --git a/drivers/Makefile b/drivers/Makefile 35index 1bec7819a837..c34686c8bc82 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_PECI) += peci/ 45 obj-$(CONFIG_HTE) += hte/ 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 8a06d0f840bc..5e3382ccdcbf 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/core \ 72+ $(HDF_ROOT_DIR)/inner_api/host/shared \ 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 e0181218ad85..57125af807d3 100644 80--- a/drivers/hid/hid-core.c 81+++ b/drivers/hid/hid-core.c 82@@ -33,6 +33,9 @@ 83 #include <linux/hid-debug.h> 84 #include <linux/hidraw.h> 85 86+#if defined(CONFIG_DRIVERS_HDF_INPUT) 87+#include "hdf_hid_adapter.h" 88+#endif 89 #include "hid-ids.h" 90 91 /* 92@@ -1541,6 +1544,11 @@ static void hid_process_event(struct hid_device *hid, struct hid_field *field, 93 hidinput_hid_event(hid, field, usage, value); 94 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event) 95 hid->hiddev_hid_event(hid, field, usage, value); 96+#if defined(CONFIG_DRIVERS_HDF_INPUT) 97+ if (hid->input_dev) { 98+ HidReportEvent(hid->input_dev, usage->type, usage->code, value); 99+ } 100+#endif 101 } 102 103 /* 104@@ -2166,6 +2174,81 @@ static const struct device_attribute dev_attr_country = { 105 .show = show_country, 106 }; 107 108+#if defined(CONFIG_DRIVERS_HDF_INPUT) 109+static bool check_mouse(char *name) 110+{ 111+ static char *option[]={"Mouse", "mouse", "MOUSE", "Razer"}; 112+ for (int i = 0; i < 4; i++) { 113+ if (strstr(name, option[i])) 114+ return true; 115+ } 116+ return false; 117+} 118+static bool check_kbd(char *name) 119+{ 120+ static char *option[]={"Keyboard", "keyboard"}; 121+ for (int i = 0; i < 2; i++) { 122+ if (strstr(name, option[i])) 123+ return true; 124+ } 125+ return false; 126+} 127+static bool check_rocker(char *name) 128+{ 129+ static char *option[]={"Thrustmaster"}; 130+ for (int i = 0; i < 1; i++) { 131+ if (strstr(name, option[i])) 132+ return true; 133+ } 134+ return false; 135+} 136+static bool check_encoder(char *name) 137+{ 138+ if (strcmp(name, "Wired KeyBoard") == 0) { 139+ return true; 140+ } 141+ return false; 142+} 143+static bool check_trackball(char *name) 144+{ 145+ static char *option[]={"Trackball"}; 146+ for (int i = 0; i < 1; i++) { 147+ if (strstr(name, option[i])) 148+ return true; 149+ } 150+ return false; 151+} 152+static void notify_connect_event(struct hid_device *hdev) 153+{ 154+ bool check; 155+ int type = -1; 156+ HidInfo *dev = (HidInfo *)kmalloc(sizeof(HidInfo), GFP_KERNEL); 157+ if (dev == NULL) { 158+ printk("%s: malloc failed", __func__); 159+ return; 160+ } 161+ type = check_mouse(hdev->name)?HID_TYPE_MOUSE:type; 162+ type = check_kbd(hdev->name)?HID_TYPE_KEYBOARD:type; 163+ type = check_rocker(hdev->name)?HID_TYPE_ROCKER:type; 164+ type = check_encoder(hdev->name)?HID_TYPE_ENCODER:type; 165+ type = check_trackball(hdev->name)?HID_TYPE_TRACKBALL:type; 166+ if ( type < 0) { 167+ kfree(dev); 168+ dev = NULL; 169+ return; 170+ } 171+ 172+ dev->devType = type; 173+ dev->devName = hdev->name; 174+ hdev->input_dev = HidRegisterHdfInputDev(dev); 175+ if (hdev->input_dev == NULL) { 176+ printk("%s: RegisterInputDevice failed\n", __func__); 177+ } 178+ kfree(dev); 179+ dev = NULL; 180+} 181+#endif 182+ 183 int hid_connect(struct hid_device *hdev, unsigned int connect_mask) 184 { 185 static const char *types[] = { "Device", "Pointer", "Mouse", "Device", 186@@ -2268,6 +2351,9 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask) 187 hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n", 188 buf, bus, hdev->version >> 8, hdev->version & 0xff, 189 type, hdev->name, hdev->phys); 190+#if defined(CONFIG_DRIVERS_HDF_INPUT) 191+ notify_connect_event(hdev); 192+#endif 193 194 return 0; 195 } 196@@ -2283,7 +2369,10 @@ void hid_disconnect(struct hid_device *hdev) 197 if (hdev->claimed & HID_CLAIMED_HIDRAW) 198 hidraw_disconnect(hdev); 199 hdev->claimed = 0; 200- 201+#if defined(CONFIG_DRIVERS_HDF_INPUT) 202+ if (hdev->input_dev) 203+ HidUnregisterHdfInputDev(hdev->input_dev); 204+#endif 205 hid_bpf_disconnect_device(hdev); 206 } 207 EXPORT_SYMBOL_GPL(hid_disconnect); 208@@ -2369,6 +2458,11 @@ EXPORT_SYMBOL_GPL(hid_hw_open); 209 */ 210 void hid_hw_close(struct hid_device *hdev) 211 { 212+#if defined(CONFIG_DRIVERS_HDF_INPUT) 213+ if (hdev->input_dev) { 214+ return; 215+ } 216+#endif 217 mutex_lock(&hdev->ll_open_lock); 218 if (!--hdev->ll_open_count) 219 hdev->ll_driver->close(hdev); 220diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c 221index c8b20d44b147..710495f014a9 100644 222--- a/drivers/hid/hid-input.c 223+++ b/drivers/hid/hid-input.c 224@@ -20,6 +20,10 @@ 225 #include <linux/hid.h> 226 #include <linux/hid-debug.h> 227 228+#if defined(CONFIG_DRIVERS_HDF_INPUT) 229+#include "hdf_hid_adapter.h" 230+#endif 231+ 232 #include "hid-ids.h" 233 234 #define unk KEY_UNKNOWN 235@@ -1745,7 +1749,15 @@ void hidinput_report_event(struct hid_device *hid, struct hid_report *report) 236 return; 237 238 list_for_each_entry(hidinput, &hid->inputs, list) 239+#if defined(CONFIG_DRIVERS_HDF_INPUT) 240+ { 241+#endif 242 input_sync(hidinput->input); 243+#if defined(CONFIG_DRIVERS_HDF_INPUT) 244+ if(hid->input_dev) 245+ HidReportEvent(hid->input_dev, EV_SYN, SYN_REPORT, 0); 246+ } 247+#endif 248 } 249 EXPORT_SYMBOL_GPL(hidinput_report_event); 250 251@@ -2267,6 +2279,41 @@ static inline void hidinput_configure_usages(struct hid_input *hidinput, 252 j); 253 } 254 255+#if defined(CONFIG_DRIVERS_HDF_INPUT) 256+static void transfer_info(struct input_dev *dev) 257+{ 258+ HidInfo *info = (HidInfo *)kmalloc(sizeof(HidInfo),GFP_KERNEL); 259+ if (info == NULL) { 260+ printk("%s: malloc failed\n",__func__); 261+ return; 262+ } 263+ info->devName = dev->name; 264+ memcpy(info->devProp, dev->propbit, sizeof(unsigned long) * BITS_TO_LONGS(INPUT_PROP_CNT)); 265+ memcpy(info->eventType, dev->evbit, sizeof(unsigned long) * BITS_TO_LONGS(EV_CNT)); 266+ memcpy(info->keyCode, dev->keybit, sizeof(unsigned long) * BITS_TO_LONGS(KEY_CNT)); 267+ memcpy(info->relCode, dev->relbit, sizeof(unsigned long) * BITS_TO_LONGS(REL_CNT)); 268+ memcpy(info->absCode, dev->absbit, sizeof(unsigned long) * BITS_TO_LONGS(ABS_CNT)); 269+ memcpy(info->miscCode, dev->mscbit, sizeof(unsigned long) * BITS_TO_LONGS(MSC_CNT)); 270+ memcpy(info->ledCode, dev->ledbit, sizeof(unsigned long) * BITS_TO_LONGS(LED_CNT)); 271+ memcpy(info->soundCode, dev->sndbit, sizeof(unsigned long) * BITS_TO_LONGS(SND_CNT)); 272+ memcpy(info->forceCode, dev->ffbit, sizeof(unsigned long) * BITS_TO_LONGS(FF_CNT)); 273+ memcpy(info->switchCode, dev->swbit, sizeof(unsigned long) * BITS_TO_LONGS(SW_CNT)); 274+ for (int i = 0; i < BITS_TO_LONGS(ABS_CNT); i++) { 275+ if (dev->absbit[i] != 0) { 276+ memcpy(info->axisInfo, dev->absinfo, sizeof(struct input_absinfo) * ABS_CNT); 277+ break; 278+ } 279+ } 280+ info->bustype = dev->id.bustype; 281+ info->vendor = dev->id.vendor; 282+ info->product = dev->id.product; 283+ info->version = dev->id.version; 284+ SendInfoToHdf(info); 285+ kfree(info); 286+ info = NULL; 287+} 288+#endif 289+ 290 /* 291 * Register the input device; print a message. 292 * Configure the input layer interface 293@@ -2352,6 +2399,9 @@ int hidinput_connect(struct hid_device *hid, unsigned int force) 294 continue; 295 } 296 297+#if defined(CONFIG_DRIVERS_HDF_INPUT) 298+ transfer_info(hidinput->input); 299+#endif 300 if (input_register_device(hidinput->input)) 301 goto out_unwind; 302 hidinput->registered = true; 303diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile 304index 04296a4abe8e..31315c7ac6ae 100644 305--- a/drivers/input/misc/Makefile 306+++ b/drivers/input/misc/Makefile 307@@ -90,3 +90,22 @@ obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o 308 obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o 309 obj-$(CONFIG_INPUT_YEALINK) += yealink.o 310 obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR) += ideapad_slidebar.o 311+ 312+ccflags-y +=-I$(srctree)/drivers/hdf/framework/model/input/driver \ 313+ -I$(srctree)/drivers/hdf/framework/model/input/driver/input_bus_ops \ 314+ -I$(srctree)/drivers/hdf/framework/include/core \ 315+ -I$(srctree)/drivers/hdf/framework/core/common/include/host \ 316+ -I$(srctree)/drivers/hdf/framework/include/utils \ 317+ -I$(srctree)/drivers/hdf/framework/include/osal \ 318+ -I$(srctree)/drivers/hdf/framework/include/platform \ 319+ -I$(srctree)/drivers/hdf/framework/include/config \ 320+ -I$(srctree)/drivers/hdf/framework/core/host/include \ 321+ -I$(srctree)/drivers/hdf/framework/core/shared/include \ 322+ -I$(srctree)/drivers/hdf/framework/utils/include \ 323+ -I$(srctree)/drivers/hdf/inner_api/osal/shared \ 324+ -I$(srctree)/drivers/hdf/inner_api/host/shared \ 325+ -I$(srctree)/drivers/hdf/inner_api/utils \ 326+ -I$(srctree)/drivers/hdf/inner_api/core \ 327+ -I$(srctree)/drivers/hdf/khdf/osal/include 328+ccflags-y +=-I$(srctree)/bounds_checking_function/include \ 329+ -I$(srctree)/drivers/hdf/evdev 330diff --git a/drivers/input/misc/rk805-pwrkey.c b/drivers/input/misc/rk805-pwrkey.c 331index 76873aa005b4..4ef4b031fdb8 100644 332--- a/drivers/input/misc/rk805-pwrkey.c 333+++ b/drivers/input/misc/rk805-pwrkey.c 334@@ -14,6 +14,9 @@ 335 #include <linux/kernel.h> 336 #include <linux/module.h> 337 #include <linux/platform_device.h> 338+#include "hdf_hid_adapter.h" 339+ 340+InputDevice *HidinputDev = NULL; 341 342 static irqreturn_t pwrkey_fall_irq(int irq, void *_pwr) 343 { 344@@ -22,6 +25,9 @@ static irqreturn_t pwrkey_fall_irq(int irq, void *_pwr) 345 input_report_key(pwr, KEY_POWER, 1); 346 input_sync(pwr); 347 348+ HidReportEvent(HidinputDev, EV_KEY, KEY_POWER, 1); 349+ HidReportEvent(HidinputDev, EV_SYN, SYN_REPORT, 0); 350+ 351 return IRQ_HANDLED; 352 } 353 354@@ -32,9 +38,25 @@ static irqreturn_t pwrkey_rise_irq(int irq, void *_pwr) 355 input_report_key(pwr, KEY_POWER, 0); 356 input_sync(pwr); 357 358+ HidReportEvent(HidinputDev, EV_KEY, KEY_POWER, 0); 359+ HidReportEvent(HidinputDev, EV_SYN, SYN_REPORT, 0); 360+ 361 return IRQ_HANDLED; 362 } 363 364+static InputDevice* HidRegisterHdfPowerKeyDev(void) 365+{ 366+ InputDevice* inputDev = NULL; 367+ HidInfo Hid_keyInfo; 368+ 369+ Hid_keyInfo.devType = HID_TYPE_KEY; 370+ Hid_keyInfo.eventType[0] = SET_BIT(EV_KEY); 371+ Hid_keyInfo.keyCode[3] = SET_BIT(KEY_POWER); 372+ Hid_keyInfo.devName = "hid-powerkey"; 373+ inputDev = HidRegisterHdfInputDev(&Hid_keyInfo); 374+ return inputDev; 375+} 376+ 377 static int rk805_pwrkey_probe(struct platform_device *pdev) 378 { 379 struct input_dev *pwr; 380@@ -87,6 +109,12 @@ static int rk805_pwrkey_probe(struct platform_device *pdev) 381 platform_set_drvdata(pdev, pwr); 382 device_init_wakeup(&pdev->dev, true); 383 384+ HidinputDev = HidRegisterHdfPowerKeyDev(); 385+ if (NULL == HidinputDev) { 386+ pr_err("HidRegisterHdfInputDev error\n"); 387+ return -EINVAL; 388+ } 389+ 390 return 0; 391 } 392 393diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c 394index 505c562a5daa..67d451beba08 100644 395--- a/drivers/input/mousedev.c 396+++ b/drivers/input/mousedev.c 397@@ -869,7 +869,7 @@ static struct mousedev *mousedev_create(struct input_dev *dev, 398 399 if (mixdev) { 400 dev_set_name(&mousedev->dev, "mice"); 401- 402+ mousedev->open = 1; 403 mousedev->open_device = mixdev_open_devices; 404 mousedev->close_device = mixdev_close_devices; 405 } else { 406diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c 407index e6143663778f..8256d576c762 100644 408--- a/drivers/usb/core/notify.c 409+++ b/drivers/usb/core/notify.c 410@@ -66,3 +66,12 @@ void usb_notify_remove_bus(struct usb_bus *ubus) 411 { 412 blocking_notifier_call_chain(&usb_notifier_list, USB_BUS_REMOVE, ubus); 413 } 414+ 415+void usb_notify_online_status(bool online) 416+{ 417+ if (online) { 418+ blocking_notifier_call_chain(&usb_notifier_list, USB_GADGET_ADD, NULL); 419+ } else { 420+ blocking_notifier_call_chain(&usb_notifier_list, USB_GADGET_REMOVE, NULL); 421+ } 422+} 423diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c 424index 28f49400f3e8..abcc53a0779c 100644 425--- a/drivers/usb/dwc3/gadget.c 426+++ b/drivers/usb/dwc3/gadget.c 427@@ -4360,6 +4360,7 @@ static void dwc3_gadget_interrupt(struct dwc3 *dwc, 428 { 429 switch (event->type) { 430 case DWC3_DEVICE_EVENT_DISCONNECT: 431+ usb_notify_online_status(false); 432 dwc3_gadget_disconnect_interrupt(dwc); 433 break; 434 case DWC3_DEVICE_EVENT_RESET: 435@@ -4367,6 +4368,7 @@ static void dwc3_gadget_interrupt(struct dwc3 *dwc, 436 break; 437 case DWC3_DEVICE_EVENT_CONNECT_DONE: 438 dwc3_gadget_conndone_interrupt(dwc); 439+ usb_notify_online_status(true); 440 break; 441 case DWC3_DEVICE_EVENT_WAKEUP: 442 dwc3_gadget_wakeup_interrupt(dwc, event->event_info); 443diff --git a/include/linux/hid.h b/include/linux/hid.h 444index 3b08a2957229..046de8cd3be0 100644 445--- a/include/linux/hid.h 446+++ b/include/linux/hid.h 447@@ -686,6 +686,7 @@ struct hid_device { /* device report descriptor */ 448 #ifdef CONFIG_BPF 449 struct hid_bpf bpf; /* hid-bpf data */ 450 #endif /* CONFIG_BPF */ 451+ void *input_dev; 452 }; 453 454 void hiddev_free(struct kref *ref); 455diff --git a/include/linux/usb.h b/include/linux/usb.h 456index a21074861f91..9e75513e4f7e 100644 457--- a/include/linux/usb.h 458+++ b/include/linux/usb.h 459@@ -2056,8 +2056,11 @@ static inline int usb_translate_errors(int error_code) 460 #define USB_DEVICE_REMOVE 0x0002 461 #define USB_BUS_ADD 0x0003 462 #define USB_BUS_REMOVE 0x0004 463+#define USB_GADGET_ADD 0x0005 464+#define USB_GADGET_REMOVE 0x0006 465 extern void usb_register_notify(struct notifier_block *nb); 466 extern void usb_unregister_notify(struct notifier_block *nb); 467+extern void usb_notify_online_status(bool online); 468 469 /* debugfs stuff */ 470 extern struct dentry *usb_debug_root; 471