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