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,19 @@ 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)/inner_api/utils \ 69+ $(HDF_ROOT_DIR)/inner_api/osal/shared \ 70+ $(HDF_ROOT_DIR)/inner_api/host/shared \ 71+ $(HDF_ROOT_DIR)/inner_api/core \ 72+ $(HDF_ROOT_DIR)/khdf/osal/include \ 73+ $(HDF_ROOT_DIR)/evdev 74 hid-y := hid-core.o hid-input.o hid-quirks.o 75 hid-$(CONFIG_DEBUG_FS) += hid-debug.o 76 77diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c 78index 5550c943f..ab16bbb73 100644 79--- a/drivers/hid/hid-core.c 80+++ b/drivers/hid/hid-core.c 81@@ -27,12 +27,16 @@ 82 #include <linux/vmalloc.h> 83 #include <linux/sched.h> 84 #include <linux/semaphore.h> 85+#include <linux/delay.h> 86 87 #include <linux/hid.h> 88 #include <linux/hiddev.h> 89 #include <linux/hid-debug.h> 90 #include <linux/hidraw.h> 91 92+#if defined(CONFIG_DRIVERS_HDF_INPUT) 93+#include "hdf_hid_adapter.h" 94+#endif 95 #include "hid-ids.h" 96 97 /* 98@@ -1522,6 +1526,11 @@ static void hid_process_event(struct hid_device *hid, struct hid_field *field, 99 hidinput_hid_event(hid, field, usage, value); 100 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event) 101 hid->hiddev_hid_event(hid, field, usage, value); 102+#if defined(CONFIG_DRIVERS_HDF_INPUT) 103+ if (hid->input_dev) { 104+ HidReportEvent(hid->input_dev, usage->type, usage->code, value); 105+ } 106+#endif 107 } 108 109 /* 110@@ -1928,6 +1937,88 @@ static const struct device_attribute dev_attr_country = { 111 .show = show_country, 112 }; 113 114+#if defined(CONFIG_DRIVERS_HDF_INPUT) 115+static bool check_mouse(char *name) 116+{ 117+ int i; 118+ static char *option[]={"Mouse", "mouse", "MOUSE", "Razer"}; 119+ for (i = 0; i < 4; i++) { 120+ if (strstr(name, option[i])) 121+ return true; 122+ } 123+ return false; 124+} 125+static bool check_kbd(char *name) 126+{ 127+ int i; 128+ static char *option[]={"Keyboard", "keyboard"}; 129+ for (i = 0; i < 2; i++) { 130+ if (strstr(name, option[i])) 131+ return true; 132+ } 133+ return false; 134+} 135+static bool check_rocker(char *name) 136+{ 137+ int i; 138+ static char *option[]={"Thrustmaster"}; 139+ for (i = 0; i < 1; i++) { 140+ if (strstr(name, option[i])) 141+ return true; 142+ } 143+ return false; 144+} 145+static bool check_encoder(char *name) 146+{ 147+ if (strcmp(name, "Wired KeyBoard") == 0) { 148+ return true; 149+ } 150+ return false; 151+} 152+static bool check_trackball(char *name) 153+{ 154+ int i; 155+ static char *option[]={"Trackball"}; 156+ for (i = 0; i < 1; i++) { 157+ if (strstr(name, option[i])) 158+ return true; 159+ } 160+ return false; 161+} 162+static void notify_connect_event(struct hid_device *hdev) 163+{ 164+ bool check; 165+ int type = -1; 166+ HidInfo *dev = (HidInfo *)kmalloc(sizeof(HidInfo), GFP_KERNEL); 167+ if (dev == NULL) { 168+ printk("%s: malloc failed", __func__); 169+ return; 170+ } 171+ type = check_mouse(hdev->name)?HID_TYPE_MOUSE:type; 172+ type = check_kbd(hdev->name)?HID_TYPE_KEYBOARD:type; 173+ type = check_rocker(hdev->name)?HID_TYPE_ROCKER:type; 174+ type = check_encoder(hdev->name)?HID_TYPE_ENCODER:type; 175+ type = check_trackball(hdev->name)?HID_TYPE_TRACKBALL:type; 176+ if ( type < 0) { 177+ kfree(dev); 178+ dev = NULL; 179+ return; 180+ } 181+ 182+ if (type == 35 || type == 36) 183+ mdelay(500); 184+ 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@@ -2020,6 +2111,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@@ -2035,6 +2129,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@@ -2119,6 +2217,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 580d37834..fb945f4ce 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@@ -1416,7 +1420,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@@ -1867,6 +1879,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@@ -1952,6 +2000,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 a48e5f2d8..90d25f224 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 3fb64dbda..394cd5912 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 505c562a5..67d451beb 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 e61436637..8256d576c 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/include/linux/hid.h b/include/linux/hid.h 433index 6ed2a97eb..1d1445a23 100644 434--- a/include/linux/hid.h 435+++ b/include/linux/hid.h 436@@ -622,6 +622,7 @@ struct hid_device { /* device report descriptor */ 437 struct list_head debug_list; 438 spinlock_t debug_list_lock; 439 wait_queue_head_t debug_wait; 440+ void *input_dev; 441 }; 442 443 #define to_hid_device(pdev) \ 444diff --git a/include/linux/usb.h b/include/linux/usb.h 445index d6a41841b..de3232ee5 100644 446--- a/include/linux/usb.h 447+++ b/include/linux/usb.h 448@@ -2019,8 +2019,11 @@ static inline int usb_translate_errors(int error_code) 449 #define USB_DEVICE_REMOVE 0x0002 450 #define USB_BUS_ADD 0x0003 451 #define USB_BUS_REMOVE 0x0004 452+#define USB_GADGET_ADD 0x0005 453+#define USB_GADGET_REMOVE 0x0006 454 extern void usb_register_notify(struct notifier_block *nb); 455 extern void usb_unregister_notify(struct notifier_block *nb); 456+extern void usb_notify_online_status(bool online); 457 458 /* debugfs stuff */ 459 extern struct dentry *usb_debug_root; 460