From 158cd445d43bfda9e16f8da7071bada58dbb059b Mon Sep 17 00:00:00 2001 From: dianlujitao Date: Fri, 2 Feb 2018 18:59:59 +0800 Subject: [PATCH] fpc1268: respect capacitive keys state * Implement a key handler with the simple purpose of filtering the key events sent by the fingerprint HAL. * Only report key event when capacitive keys enabled. * Input handler taken from bgcngm's implementation for Xiaomi msm8996. Change-Id: I091eb514fee291b7625193496c217c0b966fa518 --- .../input/fingerprint/fpc1268_tee/fpc1020_tee.c | 77 +++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/drivers/input/fingerprint/fpc1268_tee/fpc1020_tee.c b/drivers/input/fingerprint/fpc1268_tee/fpc1020_tee.c index 62933e80778a..714ae1e5453d 100644 --- a/drivers/input/fingerprint/fpc1268_tee/fpc1020_tee.c +++ b/drivers/input/fingerprint/fpc1268_tee/fpc1020_tee.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -36,8 +37,11 @@ #include #include #include +#include #include +#define FPC1020_NAME "fpc1020" + #define FPC_TTW_HOLD_TIME 2000 #define RESET_LOW_SLEEP_MIN_US 5000 @@ -82,12 +86,72 @@ struct fpc1020_data { bool prepared; atomic_t wakeup_enabled; /* Used both in ISR and non-ISR */ int irqf; + struct input_handler input_handler; }; static irqreturn_t fpc1020_irq_handler(int irq, void *handle); static int fpc1020_request_named_gpio(struct fpc1020_data *fpc1020, const char *label, int *gpio); +static int input_connect(struct input_handler *handler, + struct input_dev *dev, const struct input_device_id *id) { + int rc; + struct input_handle *handle; + struct fpc1020_data *fpc1020 = + container_of(handler, struct fpc1020_data, input_handler); + + if (!strstr(dev->name, "uinput-fpc")) + return -ENODEV; + + handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL); + if (!handle) + return -ENOMEM; + + handle->dev = dev; + handle->handler = handler; + handle->name = FPC1020_NAME; + handle->private = fpc1020; + + rc = input_register_handle(handle); + if (rc) + goto err_input_register_handle; + + rc = input_open_device(handle); + if (rc) + goto err_input_open_device; + + return 0; + +err_input_open_device: + input_unregister_handle(handle); +err_input_register_handle: + kfree(handle); + return rc; +} + +extern bool capacitive_keys_enabled; + +static bool input_filter(struct input_handle *handle, unsigned int type, + unsigned int code, int value) +{ + return !capacitive_keys_enabled; +} + +static void input_disconnect(struct input_handle *handle) +{ + input_close_device(handle); + input_unregister_handle(handle); + kfree(handle); +} + +static const struct input_device_id ids[] = { + { + .flags = INPUT_DEVICE_ID_MATCH_EVBIT, + .evbit = { BIT_MASK(EV_KEY) }, + }, + { }, +}; + static int vreg_setup(struct fpc1020_data *fpc1020, const char *name, bool enable) { @@ -577,6 +641,17 @@ static int fpc1020_probe(struct platform_device *pdev) wake_lock_init(&fpc1020->ttw_wl, WAKE_LOCK_SUSPEND, "fpc_ttw_wl"); + fpc1020->input_handler.filter = input_filter; + fpc1020->input_handler.connect = input_connect; + fpc1020->input_handler.disconnect = input_disconnect; + fpc1020->input_handler.name = FPC1020_NAME; + fpc1020->input_handler.id_table = ids; + rc = input_register_handler(&fpc1020->input_handler); + if (rc) { + dev_err(dev, "failed to register key handler\n"); + goto exit; + } + rc = sysfs_create_group(&dev->kobj, &attribute_group); if (rc) { dev_err(dev, "could not create sysfs\n"); @@ -613,7 +688,7 @@ MODULE_DEVICE_TABLE(of, fpc1020_of_match); static struct platform_driver fpc1020_driver = { .driver = { - .name = "fpc1020", + .name = FPC1020_NAME, .owner = THIS_MODULE, .of_match_table = fpc1020_of_match, }, -- 2.11.0