From ca50551fda6ca20640c9af7ca3cbc97c8360ffaf Mon Sep 17 00:00:00 2001 From: Ryan Lattrel Date: Mon, 7 Jan 2019 17:25:53 -0600 Subject: [PATCH] sx933x: add recal on flip Recalibrate the capsensor when the extcon flip device is changed. Requires an extcon parameter in the device tree node. Change-Id: I7a7408a064620fdd67a55a7f2f877d4a3542bf00 Signed-off-by: Ryan Lattrel Reviewed-on: https://gerrit.mot.com/1290732 SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Reviewed-by: Konstantin Makariev Submit-Approved: Jira Key --- drivers/misc/sx933x/Kbuild | 5 ++++ drivers/misc/sx933x/sx933x_sar.c | 42 +++++++++++++++++++++++++++++++- include/linux/input/sx933x.h | 9 +++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/misc/sx933x/Kbuild b/drivers/misc/sx933x/Kbuild index 269ebc807a63..5ac284b54368 100644 --- a/drivers/misc/sx933x/Kbuild +++ b/drivers/misc/sx933x/Kbuild @@ -11,6 +11,11 @@ EXTRA_CFLAGS += -DCONFIG_CAPSENSE_USB_CAL \ -DCONFIG_CAPSENSE_ATTACH_CAL endif +ifneq (,$(filter olson%,$(TARGET_PRODUCT))) +EXTRA_CFLAGS += -DCONFIG_CAPSENSE_USB_CAL \ + -DCONFIG_CAPSENSE_FLIP_CAL +endif + KBUILD_EXTRA_SYMBOLS += $(CURDIR)/$(KBUILD_EXTMOD)/../../sensors/Module.symvers sx932x_sar-y := sx933x_sar.o diff --git a/drivers/misc/sx933x/sx933x_sar.c b/drivers/misc/sx933x/sx933x_sar.c index 7ecabe192ede..a8acb0fd04e1 100644 --- a/drivers/misc/sx933x/sx933x_sar.c +++ b/drivers/misc/sx933x/sx933x_sar.c @@ -803,7 +803,7 @@ static int ps_notify_callback(struct notifier_block *self, bool present; int retval; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,9,0) if (event == PSY_EVENT_PROP_CHANGED #else if ((event == PSY_EVENT_PROP_ADDED || event == PSY_EVENT_PROP_CHANGED) @@ -845,6 +845,25 @@ static int ps_notify_callback(struct notifier_block *self, return 0; } + +#ifdef CONFIG_CAPSENSE_FLIP_CAL +static int flip_notify_callback(struct notifier_block *self, + unsigned long state, void *p) +{ + struct sx933x_platform_data *data = + container_of(self, struct sx933x_platform_data, flip_notif); + struct extcon_dev *edev = p; + + if(data->ext_flip_det == edev) { + if(data->phone_flip_state != state) { + data->phone_flip_state = state; + schedule_work(&data->ps_notify_work); + } + } + + return 0; +} +#endif #endif /*! \fn static int sx933x_probe(struct i2c_client *client, const struct i2c_device_id *id) @@ -1047,6 +1066,27 @@ static int sx933x_probe(struct i2c_client *client, const struct i2c_device_id *i power_supply_unreg_notifier(&pplatData->ps_notif); } } +#ifdef CONFIG_CAPSENSE_FLIP_CAL + if (of_property_read_bool(client->dev.of_node, "extcon")) { + pplatData->flip_notif.notifier_call = flip_notify_callback; + pplatData->ext_flip_det = + extcon_get_edev_by_phandle(&client->dev, 0); + if (IS_ERR(pplatData->ext_flip_det)) { + pplatData->ext_flip_det = NULL; + pr_err("%s: failed to get extcon flip dev\n", __func__); + } else { + if(extcon_register_notifier(pplatData->ext_flip_det, + EXTCON_MECHANICAL, &pplatData->flip_notif)) + pr_err("%s: failed to register extcon flip dev notifier\n", + __func__); + else + pplatData->phone_flip_state = + extcon_get_state(pplatData->ext_flip_det, + EXTCON_MECHANICAL); + } + } else + pr_err("%s: extcon not in dev tree!\n", __func__); +#endif #endif sx93XX_IRQ_init(this); diff --git a/include/linux/input/sx933x.h b/include/linux/input/sx933x.h index 01f9745fba33..28286b83a21a 100644 --- a/include/linux/input/sx933x.h +++ b/include/linux/input/sx933x.h @@ -10,6 +10,10 @@ #include #include +#ifdef CONFIG_CAPSENSE_FLIP_CAL +#include +#endif + #if 0 #include #include @@ -703,6 +707,11 @@ struct sx933x_platform_data #ifdef CONFIG_CAPSENSE_ATTACH_CAL bool phone_is_present; #endif +#ifdef CONFIG_CAPSENSE_FLIP_CAL + struct notifier_block flip_notif; + struct extcon_dev *ext_flip_det; + bool phone_flip_state; +#endif #endif pbuttonInformation_t pbuttonInformation;