From c91a6f8e9d6ca2f8e8eb6d9cebfc3bedf84ea72e Mon Sep 17 00:00:00 2001 From: haojl2 Date: Fri, 12 Jul 2019 18:26:50 +0800 Subject: [PATCH] focaltech_0flash: Enable USB detection function TP: Enable USB detection function. Increase the anti-interference ability after plugging in the USB cable. Change-Id: I64ecb13f58e87f9f687d4ad3a6725884c7304bc7 Signed-off-by: haojl2 Reviewed-on: https://gerrit.mot.com/1385264 SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Reviewed-by: Jianqi Yang Submit-Approved: Jira Key --- .../focaltech_0flash_mmi/focaltech_config.h | 5 + .../focaltech_0flash_mmi/focaltech_core.c | 113 +++++++++++++++++- .../focaltech_0flash_mmi/focaltech_core.h | 12 ++ 3 files changed, 129 insertions(+), 1 deletion(-) diff --git a/drivers/input/touchscreen/focaltech_0flash_mmi/focaltech_config.h b/drivers/input/touchscreen/focaltech_0flash_mmi/focaltech_config.h index d1d2356bb40e..4a92215734a8 100755 --- a/drivers/input/touchscreen/focaltech_0flash_mmi/focaltech_config.h +++ b/drivers/input/touchscreen/focaltech_0flash_mmi/focaltech_config.h @@ -212,6 +212,11 @@ */ #define FTS_GET_MODULE_NUM 0 +/* + * Usb detect support + */ +#define FTS_USB_DETECT_EN 1 + /* * module_id: mean vendor_id generally, also maybe gpio or lcm_id... * If means vendor_id, the FTS_MODULE_ID = PANEL_ID << 8 + VENDOR_ID diff --git a/drivers/input/touchscreen/focaltech_0flash_mmi/focaltech_core.c b/drivers/input/touchscreen/focaltech_0flash_mmi/focaltech_core.c index 6ca19304d11d..fc0545c85252 100755 --- a/drivers/input/touchscreen/focaltech_0flash_mmi/focaltech_core.c +++ b/drivers/input/touchscreen/focaltech_0flash_mmi/focaltech_core.c @@ -55,6 +55,9 @@ #define FTS_DRIVER_NAME "fts_ts" #define INTERVAL_READ_REG 200 /* unit:ms */ #define TIMEOUT_READ_REG 1000 /* unit:ms */ +#if FTS_USB_DETECT_EN +bool FTS_USB_detect_flag; +#endif #if FTS_POWER_SOURCE_CUST_EN #define FTS_VTG_MIN_UV 2800000 #define FTS_VTG_MAX_UV 3300000 @@ -666,11 +669,64 @@ static int fts_read_parse_touchdata(struct fts_ts_data *data) return 0; } +#if FTS_USB_DETECT_EN +static void fts_mcu_usb_detect_set(uint8_t usb_connected) +{ + uint8_t write_data = 0; + uint8_t read_data = 0; + uint8_t retry_cnt = 0; + int ret = 0; + + do{ + if (usb_connected == 0x01) { + write_data= 0x01; + ret = fts_write_reg(FTS_REG_CHARGER_MODE_EN, write_data); + if (ret < 0) + FTS_ERROR("set register USB IN fail, ret=%d", ret); + FTS_INFO("%s: USB detect status IN!\n", __func__); + } else { + write_data= 0x00; + ret = fts_write_reg(FTS_REG_CHARGER_MODE_EN, write_data); + if (ret < 0) + FTS_ERROR("set register USB OUT fail, ret=%d", ret); + FTS_INFO("%s: USB detect status OUT!\n", __func__); + } + + ret = fts_read_reg(FTS_REG_CHARGER_MODE_EN, &read_data); + if (ret < 0) + FTS_ERROR("read 8b register fail, ret=%d", ret); + + }while((write_data != read_data) && retry_cnt < FTS_REG_RETRY_TIMES); +} + +void fts_cable_detect_func(bool force_renew) +{ + struct fts_ts_data *ts_data = fts_data; + uint8_t connect_status = 0; + connect_status = FTS_USB_detect_flag; + + if ((connect_status != ts_data->usb_connected) || force_renew) { + if (connect_status) { + ts_data->usb_connected = 0x01; + } else { + ts_data->usb_connected = 0x00; + } + + fts_mcu_usb_detect_set(ts_data->usb_connected); + FTS_INFO("%s: Cable status change: 0x%2.2X\n", __func__, ts_data->usb_connected); + } +} +#endif + static void fts_irq_read_report(void) { int ret = 0; struct fts_ts_data *ts_data = fts_data; +#if FTS_USB_DETECT_EN + fts_cable_detect_func(false); +#endif + #if FTS_ESDCHECK_EN fts_esdcheck_set_intr(1); #endif @@ -693,6 +749,7 @@ static void fts_irq_read_report(void) #if FTS_ESDCHECK_EN fts_esdcheck_set_intr(0); #endif + } static irqreturn_t fts_irq_handler(int irq, void *data) @@ -1348,6 +1405,35 @@ static void fts_ts_late_resume(struct early_suspend *handler) } #endif +#if FTS_USB_DETECT_EN +static int fts_charger_notifier_callback(struct notifier_block *nb, + unsigned long val, void *v) { + int ret = 0; + struct power_supply *psy = NULL; + struct fts_ts_data *ts = container_of(nb, struct fts_ts_data, charger_notif); + union power_supply_propval prop; + + psy= power_supply_get_by_name("usb"); + if (!psy) { + FTS_ERROR("Couldn't get usbpsy\n"); + return -EINVAL; + } + if (!strcmp(psy->desc->name, "usb")) { + if (psy && ts && val == POWER_SUPPLY_PROP_STATUS) { + ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_PRESENT,&prop); + if (ret < 0) { + FTS_ERROR("Couldn't get POWER_SUPPLY_PROP_ONLINE rc=%d\n", ret); + return ret; + } else { + FTS_USB_detect_flag = prop.intval; + //FTS_ERROR("usb prop.intval =%d\n", prop.intval); + } + } + } + return 0; +} +#endif + static int fts_ts_probe_entry(struct fts_ts_data *ts_data) { int ret = 0; @@ -1509,9 +1595,25 @@ static int fts_ts_probe_entry(struct fts_ts_data *ts_data) register_early_suspend(&ts_data->early_suspend); #endif +#if FTS_USB_DETECT_EN + ts_data->usb_connected = 0x00; + ts_data->charger_notif.notifier_call = fts_charger_notifier_callback; + ret = power_supply_reg_notifier(&ts_data->charger_notif); + if (ret) { + FTS_ERROR("Unable to register charger_notifier: %d\n",ret); + goto err_register_charger_notify_failed; + } +#endif + FTS_FUNC_EXIT(); return 0; +#if FTS_USB_DETECT_EN +err_register_charger_notify_failed: +if (ts_data->charger_notif.notifier_call) + power_supply_unreg_notifier(&ts_data->charger_notif); +#endif + err_irq_req: #if FTS_POWER_SOURCE_CUST_EN err_power_init: @@ -1542,6 +1644,11 @@ static int fts_ts_remove_entry(struct fts_ts_data *ts_data) { FTS_FUNC_ENTER(); +#if FTS_USB_DETECT_EN + if (ts_data->charger_notif.notifier_call) + power_supply_unreg_notifier(&ts_data->charger_notif); +#endif + #if FTS_POINT_REPORT_CHECK_EN fts_point_report_check_exit(ts_data); #endif @@ -1693,8 +1800,12 @@ static int fts_ts_resume(struct device *dev) } #endif - ts_data->suspended = false; + +#if FTS_USB_DETECT_EN + fts_cable_detect_func(true); +#endif + FTS_FUNC_EXIT(); return 0; } diff --git a/drivers/input/touchscreen/focaltech_0flash_mmi/focaltech_core.h b/drivers/input/touchscreen/focaltech_0flash_mmi/focaltech_core.h index c110251eb569..f0ec30425dd8 100755 --- a/drivers/input/touchscreen/focaltech_0flash_mmi/focaltech_core.h +++ b/drivers/input/touchscreen/focaltech_0flash_mmi/focaltech_core.h @@ -62,6 +62,9 @@ #include #include #include "focaltech_common.h" +#ifdef FTS_USB_DETECT_EN +#include +#endif /***************************************************************************** * Private constant and macro definitions using #define @@ -102,6 +105,8 @@ #define FTX_MAX_COMPATIBLE_TYPE 4 #define FTX_MAX_COMMMAND_LENGTH 16 +#define FTS_REG_RETRY_TIMES 5 + /***************************************************************************** * Private enumerations, structures and unions using typedef @@ -185,11 +190,18 @@ struct fts_ts_data { struct pinctrl_state *pins_suspend; struct pinctrl_state *pins_release; #endif + #if defined(CONFIG_FB) || defined(CONFIG_DRM) struct notifier_block fb_notif; #elif defined(CONFIG_HAS_EARLYSUSPEND) struct early_suspend early_suspend; #endif + +#if FTS_USB_DETECT_EN + uint8_t usb_connected; + struct notifier_block charger_notif; +#endif + }; /*****************************************************************************