1From 8eb9130f982035d9cc9071907b4e341e52331865 Mon Sep 17 00:00:00 2001 2From: ygopenhm <ygopenhm@vyagoo.com> 3Date: Wed, 28 Sep 2022 20:32:57 +0800 4Subject: [PATCH] hdf 5 6Signed-off-by: ygopenhm <ygopenhm@vyagoo.com> 7--- 8 Makefile | 4 +- 9 arch/arm/kernel/vmlinux.lds.S | 8 +++ 10 arch/arm64/Makefile | 3 +- 11 arch/arm64/kernel/vmlinux.lds.S | 8 +++ 12 drivers/Kconfig | 2 + 13 drivers/Makefile | 1 + 14 drivers/hdf/Makefile | 2 + 15 drivers/hid/Makefile | 9 +++ 16 drivers/hid/hid-core.c | 99 +++++++++++++++++++++++++++++++++ 17 drivers/hid/hid-input.c | 51 +++++++++++++++++ 18 drivers/input/misc/Makefile | 14 +++++ 19 drivers/input/mousedev.c | 2 +- 20 include/linux/hid.h | 1 + 21 13 files changed, 199 insertions(+), 5 deletions(-) 22 create mode 100755 drivers/hdf/Makefile 23 24diff --git a/Makefile b/Makefile 25index 50696cff4..a45981b4f 100644 26--- a/Makefile 27+++ b/Makefile 28@@ -494,7 +494,7 @@ LINUXINCLUDE := \ 29 $(USERINCLUDE) 30 31 KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE 32-KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \ 33+KBUILD_CFLAGS := -Wall -Wundef -Wno-trigraphs \ 34 -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \ 35 -Werror=implicit-function-declaration -Werror=implicit-int \ 36 -Werror=return-type -Wno-format-security \ 37@@ -985,7 +985,7 @@ KBUILD_CFLAGS += $(call cc-option,-fconserve-stack) 38 KBUILD_CFLAGS += -Werror=date-time 39 40 # enforce correct pointer usage 41-KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types) 42+KBUILD_CFLAGS += $(call cc-option,-Wno=incompatible-pointer-types) 43 44 # Require designated initializers for all marked structures 45 KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init) 46diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S 47index 8af654bd1..1e9ff41d6 100644 48--- a/arch/arm/kernel/vmlinux.lds.S 49+++ b/arch/arm/kernel/vmlinux.lds.S 50@@ -131,6 +131,14 @@ SECTIONS 51 __pv_table_end = .; 52 } 53 54+#ifdef CONFIG_DRIVERS_HDF 55+ .init.hdf_table : { 56+ _hdf_drivers_start = .; 57+ *(.hdf.driver) 58+ _hdf_drivers_end = .; 59+ } 60+#endif 61+ 62 INIT_DATA_SECTION(16) 63 64 .exit.data : { 65diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile 66index 485b7dbd4..ff0326c8c 100644 67--- a/arch/arm64/Makefile 68+++ b/arch/arm64/Makefile 69@@ -44,8 +44,7 @@ ifeq ($(CONFIG_BROKEN_GAS_INST),y) 70 $(warning Detected assembler with broken .inst; disassembly will be unreliable) 71 endif 72 73-KBUILD_CFLAGS += -mgeneral-regs-only \ 74- $(compat_vdso) $(cc_has_k_constraint) 75+KBUILD_CFLAGS += $(compat_vdso) $(cc_has_k_constraint) 76 KBUILD_CFLAGS += $(call cc-disable-warning, psabi) 77 KBUILD_AFLAGS += $(compat_vdso) 78 79diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S 80index 31fdb55cd..17147bbad 100644 81--- a/arch/arm64/kernel/vmlinux.lds.S 82+++ b/arch/arm64/kernel/vmlinux.lds.S 83@@ -201,6 +201,14 @@ SECTIONS 84 INIT_RAM_FS 85 *(.init.altinstructions .init.rodata.* .init.bss) /* from the EFI stub */ 86 } 87+ 88+#ifdef CONFIG_DRIVERS_HDF 89+ .init.hdf_table : { 90+ _hdf_drivers_start = .; 91+ *(.hdf.driver) 92+ _hdf_drivers_end = .; 93+ } 94+#endif 95 .exit.data : { 96 EXIT_DATA 97 } 98diff --git a/drivers/Kconfig b/drivers/Kconfig 99index 3584901f1..12e0cceac 100644 100--- a/drivers/Kconfig 101+++ b/drivers/Kconfig 102@@ -236,6 +236,8 @@ source "drivers/interconnect/Kconfig" 103 104 source "drivers/counter/Kconfig" 105 106+source "drivers/hdf/khdf/Kconfig" 107+ 108 source "drivers/most/Kconfig" 109 110 source "drivers/accesstokenid/Kconfig" 111diff --git a/drivers/Makefile b/drivers/Makefile 112index f13d70df6..8ec75883a 100644 113--- a/drivers/Makefile 114+++ b/drivers/Makefile 115@@ -191,6 +191,7 @@ obj-$(CONFIG_SIOX) += siox/ 116 obj-$(CONFIG_GNSS) += gnss/ 117 obj-$(CONFIG_INTERCONNECT) += interconnect/ 118 obj-$(CONFIG_COUNTER) += counter/ 119+obj-$(CONFIG_DRIVERS_HDF) += hdf/ 120 obj-$(CONFIG_MOST) += most/ 121 obj-$(CONFIG_ACCESS_TOKENID) += accesstokenid/ 122 obj-$(CONFIG_VENDOR_HOOKS) += hooks/ 123diff --git a/drivers/hdf/Makefile b/drivers/hdf/Makefile 124new file mode 100755 125index 000000000..5c5e1911c 126--- /dev/null 127+++ b/drivers/hdf/Makefile 128@@ -0,0 +1,2 @@ 129+export PROJECT_ROOT := ../../../../../ 130+obj-$(CONFIG_DRIVERS_HDF) += khdf/ 131diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile 132index 4acb583c9..ddcaf4cdc 100644 133--- a/drivers/hid/Makefile 134+++ b/drivers/hid/Makefile 135@@ -2,6 +2,15 @@ 136 # 137 # Makefile for the HID driver 138 # 139+HDF_ROOT_DIR = -I$(srctree)/drivers/hdf 140+ccflags-$(CONFIG_DRIVERS_HDF_INPUT) += $(HDF_ROOT_DIR)/framework/model/input/driver \ 141+ $(HDF_ROOT_DIR)/framework/include/core \ 142+ $(HDF_ROOT_DIR)/framework/core/common/include/host \ 143+ $(HDF_ROOT_DIR)/framework/include/utils \ 144+ $(HDF_ROOT_DIR)/framework/include/osal \ 145+ $(HDF_ROOT_DIR)/framework/ability/sbuf/include \ 146+ $(HDF_ROOT_DIR)/khdf/osal/include \ 147+ $(HDF_ROOT_DIR)/evdev 148 hid-y := hid-core.o hid-input.o hid-quirks.o 149 hid-$(CONFIG_DEBUG_FS) += hid-debug.o 150 151diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c 152index 5550c943f..f0503e232 100644 153--- a/drivers/hid/hid-core.c 154+++ b/drivers/hid/hid-core.c 155@@ -33,6 +33,9 @@ 156 #include <linux/hid-debug.h> 157 #include <linux/hidraw.h> 158 159+#if defined(CONFIG_DRIVERS_HDF_INPUT) 160+#include "hdf_hid_adapter.h" 161+#endif 162 #include "hid-ids.h" 163 164 /* 165@@ -1522,6 +1525,11 @@ static void hid_process_event(struct hid_device *hid, struct hid_field *field, 166 hidinput_hid_event(hid, field, usage, value); 167 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event) 168 hid->hiddev_hid_event(hid, field, usage, value); 169+#if defined(CONFIG_DRIVERS_HDF_INPUT) 170+ if (hid->input_dev) { 171+ HidReportEvent(hid->input_dev, usage->type, usage->code, value); 172+ } 173+#endif 174 } 175 176 /* 177@@ -1928,6 +1936,85 @@ static const struct device_attribute dev_attr_country = { 178 .show = show_country, 179 }; 180 181+#if defined(CONFIG_DRIVERS_HDF_INPUT) 182+static bool check_mouse(char *name) 183+{ 184+ int i; 185+ static char *option[]={"Mouse", "mouse", "MOUSE", "Razer"}; 186+ for (i = 0; i < 4; i++) { 187+ if (strstr(name, option[i])) 188+ return true; 189+ } 190+ return false; 191+} 192+static bool check_kbd(char *name) 193+{ 194+ int i; 195+ static char *option[]={"Keyboard", "keyboard"}; 196+ for (i = 0; i < 2; i++) { 197+ if (strstr(name, option[i])) 198+ return true; 199+ } 200+ return false; 201+} 202+static bool check_rocker(char *name) 203+{ 204+ int i; 205+ static char *option[]={"Thrustmaster"}; 206+ for (i = 0; i < 1; i++) { 207+ if (strstr(name, option[i])) 208+ return true; 209+ } 210+ return false; 211+} 212+static bool check_encoder(char *name) 213+{ 214+ if (strcmp(name, "Wired KeyBoard") == 0) { 215+ return true; 216+ } 217+ return false; 218+} 219+static bool check_trackball(char *name) 220+{ 221+ int i; 222+ static char *option[]={"Trackball"}; 223+ for (i = 0; i < 1; i++) { 224+ if (strstr(name, option[i])) 225+ return true; 226+ } 227+ return false; 228+} 229+static void notify_connect_event(struct hid_device *hdev) 230+{ 231+ bool check; 232+ int type = -1; 233+ HidInfo *dev = (HidInfo *)kmalloc(sizeof(HidInfo), GFP_KERNEL); 234+ if (dev == NULL) { 235+ printk("%s: malloc failed", __func__); 236+ return; 237+ } 238+ type = check_mouse(hdev->name)?HID_TYPE_MOUSE:type; 239+ type = check_kbd(hdev->name)?HID_TYPE_KEYBOARD:type; 240+ type = check_rocker(hdev->name)?HID_TYPE_ROCKER:type; 241+ type = check_encoder(hdev->name)?HID_TYPE_ENCODER:type; 242+ type = check_trackball(hdev->name)?HID_TYPE_TRACKBALL:type; 243+ if ( type < 0) { 244+ kfree(dev); 245+ dev = NULL; 246+ return; 247+ } 248+ 249+ dev->devType = type; 250+ dev->devName = hdev->name; 251+ hdev->input_dev = HidRegisterHdfInputDev(dev); 252+ if (hdev->input_dev == NULL) { 253+ printk("%s: RegisterInputDevice failed\n", __func__); 254+ } 255+ kfree(dev); 256+ dev = NULL; 257+} 258+#endif 259+ 260 int hid_connect(struct hid_device *hdev, unsigned int connect_mask) 261 { 262 static const char *types[] = { "Device", "Pointer", "Mouse", "Device", 263@@ -2020,6 +2107,9 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask) 264 hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n", 265 buf, bus, hdev->version >> 8, hdev->version & 0xff, 266 type, hdev->name, hdev->phys); 267+#if defined(CONFIG_DRIVERS_HDF_INPUT) 268+ notify_connect_event(hdev); 269+#endif 270 271 return 0; 272 } 273@@ -2035,6 +2125,10 @@ void hid_disconnect(struct hid_device *hdev) 274 if (hdev->claimed & HID_CLAIMED_HIDRAW) 275 hidraw_disconnect(hdev); 276 hdev->claimed = 0; 277+#if defined(CONFIG_DRIVERS_HDF_INPUT) 278+ if (hdev->input_dev) 279+ HidUnregisterHdfInputDev(hdev->input_dev); 280+#endif 281 } 282 EXPORT_SYMBOL_GPL(hid_disconnect); 283 284@@ -2119,6 +2213,11 @@ EXPORT_SYMBOL_GPL(hid_hw_open); 285 */ 286 void hid_hw_close(struct hid_device *hdev) 287 { 288+#if defined(CONFIG_DRIVERS_HDF_INPUT) 289+ if (hdev->input_dev) { 290+ return; 291+ } 292+#endif 293 mutex_lock(&hdev->ll_open_lock); 294 if (!--hdev->ll_open_count) 295 hdev->ll_driver->close(hdev); 296diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c 297index 580d37834..fb945f4ce 100644 298--- a/drivers/hid/hid-input.c 299+++ b/drivers/hid/hid-input.c 300@@ -20,6 +20,10 @@ 301 #include <linux/hid.h> 302 #include <linux/hid-debug.h> 303 304+#if defined(CONFIG_DRIVERS_HDF_INPUT) 305+#include "hdf_hid_adapter.h" 306+#endif 307+ 308 #include "hid-ids.h" 309 310 #define unk KEY_UNKNOWN 311@@ -1416,7 +1420,15 @@ void hidinput_report_event(struct hid_device *hid, struct hid_report *report) 312 return; 313 314 list_for_each_entry(hidinput, &hid->inputs, list) 315+#if defined(CONFIG_DRIVERS_HDF_INPUT) 316+ { 317+#endif 318 input_sync(hidinput->input); 319+#if defined(CONFIG_DRIVERS_HDF_INPUT) 320+ if(hid->input_dev) 321+ HidReportEvent(hid->input_dev, EV_SYN, SYN_REPORT, 0); 322+ } 323+#endif 324 } 325 EXPORT_SYMBOL_GPL(hidinput_report_event); 326 327@@ -1867,6 +1879,42 @@ static inline void hidinput_configure_usages(struct hid_input *hidinput, 328 report->field[i]->usage + j); 329 } 330 331+#if defined(CONFIG_DRIVERS_HDF_INPUT) 332+static void transfer_info(struct input_dev *dev) 333+{ 334+ int i; 335+ HidInfo *info = (HidInfo *)kmalloc(sizeof(HidInfo),GFP_KERNEL); 336+ if (info == NULL) { 337+ printk("%s: malloc failed\n",__func__); 338+ return; 339+ } 340+ info->devName = dev->name; 341+ memcpy(info->devProp, dev->propbit, sizeof(unsigned long) * BITS_TO_LONGS(INPUT_PROP_CNT)); 342+ memcpy(info->eventType, dev->evbit, sizeof(unsigned long) * BITS_TO_LONGS(EV_CNT)); 343+ memcpy(info->keyCode, dev->keybit, sizeof(unsigned long) * BITS_TO_LONGS(KEY_CNT)); 344+ memcpy(info->relCode, dev->relbit, sizeof(unsigned long) * BITS_TO_LONGS(REL_CNT)); 345+ memcpy(info->absCode, dev->absbit, sizeof(unsigned long) * BITS_TO_LONGS(ABS_CNT)); 346+ memcpy(info->miscCode, dev->mscbit, sizeof(unsigned long) * BITS_TO_LONGS(MSC_CNT)); 347+ memcpy(info->ledCode, dev->ledbit, sizeof(unsigned long) * BITS_TO_LONGS(LED_CNT)); 348+ memcpy(info->soundCode, dev->sndbit, sizeof(unsigned long) * BITS_TO_LONGS(SND_CNT)); 349+ memcpy(info->forceCode, dev->ffbit, sizeof(unsigned long) * BITS_TO_LONGS(FF_CNT)); 350+ memcpy(info->switchCode, dev->swbit, sizeof(unsigned long) * BITS_TO_LONGS(SW_CNT)); 351+ for (i = 0; i < BITS_TO_LONGS(ABS_CNT); i++) { 352+ if (dev->absbit[i] != 0) { 353+ memcpy(info->axisInfo, dev->absinfo, sizeof(struct input_absinfo) * ABS_CNT); 354+ break; 355+ } 356+ } 357+ info->bustype = dev->id.bustype; 358+ info->vendor = dev->id.vendor; 359+ info->product = dev->id.product; 360+ info->version = dev->id.version; 361+ SendInfoToHdf(info); 362+ kfree(info); 363+ info = NULL; 364+} 365+#endif 366+ 367 /* 368 * Register the input device; print a message. 369 * Configure the input layer interface 370@@ -1952,6 +2000,9 @@ int hidinput_connect(struct hid_device *hid, unsigned int force) 371 continue; 372 } 373 374+#if defined(CONFIG_DRIVERS_HDF_INPUT) 375+ transfer_info(hidinput->input); 376+#endif 377 if (input_register_device(hidinput->input)) 378 goto out_unwind; 379 hidinput->registered = true; 380diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile 381index a48e5f2d8..2a1480815 100644 382--- a/drivers/input/misc/Makefile 383+++ b/drivers/input/misc/Makefile 384@@ -85,3 +85,17 @@ obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o 385 obj-$(CONFIG_INPUT_YEALINK) += yealink.o 386 obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR) += ideapad_slidebar.o 387 388+ccflags-y +=-I$(srctree)/drivers/hdf/framework/model/input/driver \ 389+ -I$(srctree)/drivers/hdf/framework/model/input/driver/input_bus_ops \ 390+ -I$(srctree)/drivers/hdf/framework/include/core \ 391+ -I$(srctree)/drivers/hdf/framework/core/common/include/host \ 392+ -I$(srctree)/drivers/hdf/framework/include/utils \ 393+ -I$(srctree)/drivers/hdf/framework/include/osal \ 394+ -I$(srctree)/drivers/hdf/framework/include/platform \ 395+ -I$(srctree)/drivers/hdf/framework/include/config \ 396+ -I$(srctree)/drivers/hdf/framework/core/host/include \ 397+ -I$(srctree)/drivers/hdf/framework/core/shared/include \ 398+ -I$(srctree)/drivers/hdf/framework/utils/include \ 399+ -I$(srctree)/drivers/hdf/khdf/osal/include 400+ccflags-y +=-I$(srctree)/bounds_checking_function/include \ 401+ -I$(srctree)/drivers/hdf/evdev 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/include/linux/hid.h b/include/linux/hid.h 416index fc56d53cc..90822e3d3 100644 417--- a/include/linux/hid.h 418+++ b/include/linux/hid.h 419@@ -622,6 +622,7 @@ struct hid_device { /* device report descriptor */ 420 struct list_head debug_list; 421 spinlock_t debug_list_lock; 422 wait_queue_head_t debug_wait; 423+ void *input_dev; 424 }; 425 426 #define to_hid_device(pdev) \ 427-- 4282.25.1 429 430