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