From 73a94e5640d6ad461049201068a481dadd4bea2d Mon Sep 17 00:00:00 2001 From: Muhammed Efe Cetin Date: Sun, 6 Oct 2024 23:52:41 +0300 Subject: [PATCH] input: touchscreen: gt1x: support to keep otp config --- drivers/input/touchscreen/gt1x/gt1x.c | 6 ++++ drivers/input/touchscreen/gt1x/gt1x_generic.c | 29 ++++++++++++++----- drivers/input/touchscreen/gt1x/gt1x_generic.h | 1 + 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/drivers/input/touchscreen/gt1x/gt1x.c b/drivers/input/touchscreen/gt1x/gt1x.c index 7d54cd651ea2a..8f714f30f154d 100644 --- a/drivers/input/touchscreen/gt1x/gt1x.c +++ b/drivers/input/touchscreen/gt1x/gt1x.c @@ -364,6 +364,12 @@ static int gt1x_parse_dt(struct device *dev) } #endif +#if GTP_DRIVER_SEND_CFG + gt1x_keep_otp_config = of_property_read_bool(dev->of_node, "keep-otp-config"); +#else + gt1x_keep_otp_config = true; +#endif + return 0; } diff --git a/drivers/input/touchscreen/gt1x/gt1x_generic.c b/drivers/input/touchscreen/gt1x/gt1x_generic.c index 132fabdd6f9fd..cd137346c475f 100644 --- a/drivers/input/touchscreen/gt1x/gt1x_generic.c +++ b/drivers/input/touchscreen/gt1x/gt1x_generic.c @@ -73,6 +73,7 @@ u32 gt1x_abs_x_max; u32 gt1x_abs_y_max; int gt1x_halt; bool gt1x_ics_slot_report; +bool gt1x_keep_otp_config; #if GTP_DEBUG_NODE static ssize_t gt1x_debug_read_proc(struct file *, char __user *, size_t, loff_t *); @@ -629,14 +630,26 @@ s32 gt1x_init_panel(void) } set_reg_bit(gt1x_config[MODULE_SWITCH3_LOC], 5, !gt1x_wakeup_level); #endif /* END GTP_CUSTOM_CFG */ +#endif /* END GTP_DRIVER_SEND_CFG */ -#else /* DRIVER NOT SEND CONFIG */ - cfg_len = GTP_CONFIG_MAX_LENGTH; - ret = gt1x_i2c_read(GTP_REG_CONFIG_DATA, gt1x_config, cfg_len); - if (ret < 0) { - return ret; + if (gt1x_keep_otp_config) { + cfg_len = GTP_CONFIG_MAX_LENGTH; + ret = gt1x_i2c_read(GTP_REG_CONFIG_DATA, gt1x_config, cfg_len); + if (ret < 0) { + GTP_ERROR("Failed to read CONFIG data, sensor_id %d", gt1x_version.sensor_id); + return ret; + } else { + int i; + u16 checksum = 0; + for (i = 0; i < cfg_len - 4; i += 2) { + checksum += (gt1x_config[i] << 8) + gt1x_config[i + 1]; + } + checksum = 0 - checksum; + if (!checksum || checksum != ((gt1x_config[i] << 8) + gt1x_config[i + 1])) { + GTP_ERROR("Invalid config data, checksum %04x", checksum); + } + } } -#endif /* END GTP_DRIVER_SEND_CFG */ GTP_DEBUG_FUNC(); /* match resolution when gt1x_abs_x_max & gt1x_abs_y_max have been set already */ @@ -657,7 +670,9 @@ s32 gt1x_init_panel(void) GTP_INFO("X_MAX=%d,Y_MAX=%d,TRIGGER=0x%02x,WAKEUP_LEVEL=%d", gt1x_abs_x_max, gt1x_abs_y_max, gt1x_int_type, gt1x_wakeup_level); gt1x_cfg_length = cfg_len; - ret = gt1x_send_cfg(gt1x_config, gt1x_cfg_length); + if (!gt1x_keep_otp_config) { + ret = gt1x_send_cfg(gt1x_config, gt1x_cfg_length); + } return ret; } diff --git a/drivers/input/touchscreen/gt1x/gt1x_generic.h b/drivers/input/touchscreen/gt1x/gt1x_generic.h index f73e18283ea71..ac77f05df1aab 100644 --- a/drivers/input/touchscreen/gt1x/gt1x_generic.h +++ b/drivers/input/touchscreen/gt1x/gt1x_generic.h @@ -534,6 +534,7 @@ extern s32 gt1x_i2c_read(u16 addr, u8 *buffer, s32 len); extern s32 gt1x_i2c_read_dbl_check(u16 addr, u8 *buffer, s32 len); extern bool gt1x_ics_slot_report; +extern bool gt1x_keep_otp_config; extern u8 gt1x_config[]; extern u32 gt1x_cfg_length; extern u8 gt1x_int_type;