From e89bd60d41248d18fbada8bb71c2a583859b654c Mon Sep 17 00:00:00 2001 From: Zhibang Li Date: Thu, 7 Sep 2023 18:59:31 +0800 Subject: [PATCH] Hall sensor add passive pen code Modify hall_pen.c file to add pen detection code Modify Android.mk and Kbuild to add definition Change-Id: Ica36be5f69eeb5205bc9d7573a6801602d4db7a0 Signed-off-by: Zhibang Li Reviewed-on: https://gerrit.mot.com/2733379 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Lijun Chen Reviewed-by: Yeqing Wang Reviewed-by: Huosheng Liao Submit-Approved: Jira Key --- drivers/misc/hall/Android.mk | 4 +++ drivers/misc/hall/Kbuild | 4 +++ drivers/misc/hall/hall_pen.c | 56 ++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/drivers/misc/hall/Android.mk b/drivers/misc/hall/Android.mk index a9547d4e434c..8ef8a0f6959d 100644 --- a/drivers/misc/hall/Android.mk +++ b/drivers/misc/hall/Android.mk @@ -1,6 +1,10 @@ DLKM_DIR := motorola/kernel/modules LOCAL_PATH := $(call my-dir) +ifeq ($(HALL_PASSIVE_PEN),true) + KBUILD_OPTIONS += CONFIG_HALL_PASSIVE_PEN=y +endif + include $(CLEAR_VARS) LOCAL_MODULE := hall_pen.ko LOCAL_MODULE_TAGS := optional diff --git a/drivers/misc/hall/Kbuild b/drivers/misc/hall/Kbuild index b69f7acf630b..84a1c7902335 100644 --- a/drivers/misc/hall/Kbuild +++ b/drivers/misc/hall/Kbuild @@ -8,6 +8,10 @@ KERNEL_PLATFORM_PATH = $(shell find $(ANDROID_BUILD_TOP) -maxdepth 1 -name "kern EXTRA_CFLAGS += -Wall EXTRA_CFLAGS += -I$(ANDROID_BUILD_TOP)/motorola/kernel/modules/include +ifneq ($(filter m y,$(CONFIG_HALL_PASSIVE_PEN)),) + EXTRA_CFLAGS += -DCONFIG_HALL_PASSIVE_PEN +endif + KBUILD_EXTRA_SYMBOLS += $(CURDIR)/$(KBUILD_EXTMOD)/../../sensors/$(GKI_OBJ_MODULE_DIR)/Module.symvers diff --git a/drivers/misc/hall/hall_pen.c b/drivers/misc/hall/hall_pen.c index af2b420073c8..9849b412a053 100644 --- a/drivers/misc/hall/hall_pen.c +++ b/drivers/misc/hall/hall_pen.c @@ -21,6 +21,9 @@ #include #include #include +#ifdef CONFIG_HALL_PASSIVE_PEN +#include +#endif #define DRIVER_NAME "hall_pen_detect" #define LOG_DBG(fmt, args...) pr_debug(DRIVER_NAME " [DBG]" "<%s:%d>"fmt, __func__, __LINE__, ##args) @@ -70,6 +73,50 @@ static struct platform_driver hall_pen_driver = { }, }; +#ifdef CONFIG_HALL_PASSIVE_PEN +static BLOCKING_NOTIFIER_HEAD(pen_detection_notifier_list); + +/** + * pen_detection_register_client - register a client notifier + * @nb: notifier block to callback on events + * + * This function registers a notifier callback function + * to pen_detection_notifier_list, which would be called when + * the passive pen is inserted or pulled out. + */ +int pen_detection_register_client(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&pen_detection_notifier_list, + nb); +} +EXPORT_SYMBOL(pen_detection_register_client); + +/** + * pen_detection_unregister_client - unregister a client notifier + * @nb: notifier block to callback on events + * + * This function unregisters the callback function from + * pen_detection_notifier_list. + */ +int pen_detection_unregister_client(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&pen_detection_notifier_list, + nb); +} +EXPORT_SYMBOL(pen_detection_unregister_client); + +/** + * pen_detection_notifier_call_chain - notify clients of pen_detection_events + * @val: event PEN_DETECTION_INSERT or PEN_DETECTION_PULL + * @v: notifier data, inculde display pen detection event. + */ +static int pen_detection_notifier_call_chain(unsigned long val, void *v) +{ + return blocking_notifier_call_chain(&pen_detection_notifier_list, val, + v); +} +#endif + void check_and_send(void) { int i; @@ -89,6 +136,13 @@ void check_and_send(void) input_report_abs(hall_sensor_dev->hall_dev, ABS_DISTANCE, report_val); input_sync(hall_sensor_dev->hall_dev); } + +#ifdef CONFIG_HALL_PASSIVE_PEN + if(hall_sensor_dev->report_val) + pen_detection_notifier_call_chain(PEN_DETECTION_INSERT, NULL); + else + pen_detection_notifier_call_chain(PEN_DETECTION_PULL, NULL); +#endif } void hall_enable(bool enable) @@ -294,7 +348,9 @@ static int hall_sensor_probe(struct platform_device *pdev) hall_sensor_dev->gpio_list[i].irq = 0; goto fail_for_irq; } +#ifndef CONFIG_HALL_PASSIVE_PEN disable_irq(hall_sensor_dev->gpio_list[i].irq); +#endif } }