From a426129cba5edce1162f5dbe7d34dd31c013e7ff Mon Sep 17 00:00:00 2001 From: Jens Reidel Date: Fri, 6 Sep 2024 23:46:22 +0200 Subject: [PATCH] input: touchscreen: goodix_berlin_driver: Get IC type from matched compatible Change-Id: I45123063402b3bbeac99288ccdb4ae2c3280698c Signed-off-by: Jens Reidel --- .../goodix_berlin_driver/goodix_brl_i2c.c | 22 +++++++++---------- .../goodix_berlin_driver/goodix_brl_spi.c | 22 +++++++++---------- .../goodix_berlin_driver/goodix_ts_core.h | 2 +- .../goodix_berlin_driver/goodix_ts_utils.c | 19 ++++++++-------- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/drivers/input/touchscreen/goodix_berlin_driver/goodix_brl_i2c.c b/drivers/input/touchscreen/goodix_berlin_driver/goodix_brl_i2c.c index 3767c95e9901..86096ed9fb49 100644 --- a/drivers/input/touchscreen/goodix_berlin_driver/goodix_brl_i2c.c +++ b/drivers/input/touchscreen/goodix_berlin_driver/goodix_brl_i2c.c @@ -161,6 +161,16 @@ static void goodix_pdev_release(struct device *dev) kfree(goodix_pdev); } +#ifdef CONFIG_OF +static const struct of_device_id i2c_matchs[] = { + {.compatible = "goodix,gt9897",}, + {.compatible = "goodix,gt9966",}, + {.compatible = "goodix,gt9916",}, + {}, +}; +MODULE_DEVICE_TABLE(of, i2c_matchs); +#endif + static int goodix_i2c_probe(struct i2c_client *client, const struct i2c_device_id *dev_id) { @@ -172,7 +182,7 @@ static int goodix_i2c_probe(struct i2c_client *client, return -EIO; /* get ic type */ - ret = goodix_get_ic_type(client->dev.of_node); + ret = goodix_get_ic_type(client->dev.of_node, i2c_matchs); if (ret < 0) return ret; @@ -221,16 +231,6 @@ static int goodix_i2c_remove(struct i2c_client *client) return 0; } -#ifdef CONFIG_OF -static const struct of_device_id i2c_matchs[] = { - {.compatible = "goodix,gt9897",}, - {.compatible = "goodix,gt9966",}, - {.compatible = "goodix,gt9916",}, - {}, -}; -MODULE_DEVICE_TABLE(of, i2c_matchs); -#endif - static const struct i2c_device_id i2c_id_table[] = { {TS_DRIVER_NAME, 0}, {}, diff --git a/drivers/input/touchscreen/goodix_berlin_driver/goodix_brl_spi.c b/drivers/input/touchscreen/goodix_berlin_driver/goodix_brl_spi.c index 7dbe405ad11b..e5b75a2fd5e9 100644 --- a/drivers/input/touchscreen/goodix_berlin_driver/goodix_brl_spi.c +++ b/drivers/input/touchscreen/goodix_berlin_driver/goodix_brl_spi.c @@ -189,6 +189,16 @@ static void goodix_pdev_release(struct device *dev) kfree(goodix_pdev); } +#ifdef CONFIG_OF +static const struct of_device_id spi_matchs[] = { + {.compatible = "goodix,gt9897S",}, + {.compatible = "goodix,gt9897T",}, + {.compatible = "goodix,gt9966S",}, + {.compatible = "goodix,gt9916S",}, + {}, +}; +#endif + static int goodix_spi_probe(struct spi_device *spi) { int ret = 0; @@ -206,7 +216,7 @@ static int goodix_spi_probe(struct spi_device *spi) } /* get ic type */ - ret = goodix_get_ic_type(spi->dev.of_node); + ret = goodix_get_ic_type(spi->dev.of_node, spi_matchs); if (ret < 0) return ret; @@ -259,16 +269,6 @@ static int goodix_spi_remove(struct spi_device *spi) return 0; } -#ifdef CONFIG_OF -static const struct of_device_id spi_matchs[] = { - {.compatible = "goodix,gt9897S",}, - {.compatible = "goodix,gt9897T",}, - {.compatible = "goodix,gt9966S",}, - {.compatible = "goodix,gt9916S",}, - {}, -}; -#endif - static const struct spi_device_id spi_id_table[] = { {TS_DRIVER_NAME, 0}, {}, diff --git a/drivers/input/touchscreen/goodix_berlin_driver/goodix_ts_core.h b/drivers/input/touchscreen/goodix_berlin_driver/goodix_ts_core.h index 4c6ee209cc8d..8ba5951f0ad0 100644 --- a/drivers/input/touchscreen/goodix_berlin_driver/goodix_ts_core.h +++ b/drivers/input/touchscreen/goodix_berlin_driver/goodix_ts_core.h @@ -694,7 +694,7 @@ int goodix_fw_update_init(struct goodix_ts_core *core_data); void goodix_fw_update_uninit(void); int goodix_do_fw_update(struct goodix_ic_config *ic_config, int mode); -int goodix_get_ic_type(struct device_node *node); +int goodix_get_ic_type(struct device_node *node, const struct of_device_id *goodix_dt_ids); int gesture_module_init(void); void gesture_module_exit(void); int inspect_module_init(void); diff --git a/drivers/input/touchscreen/goodix_berlin_driver/goodix_ts_utils.c b/drivers/input/touchscreen/goodix_berlin_driver/goodix_ts_utils.c index 6d55eb3d9eda..cc5c4e2f2352 100644 --- a/drivers/input/touchscreen/goodix_berlin_driver/goodix_ts_utils.c +++ b/drivers/input/touchscreen/goodix_berlin_driver/goodix_ts_utils.c @@ -150,24 +150,25 @@ void goodix_rotate_abcd2cbad(int tx, int rx, s16 *data) } /* get ic type */ -int goodix_get_ic_type(struct device_node *node) +int goodix_get_ic_type(struct device_node *node, const struct of_device_id *goodix_dt_ids) { - const char *name_tmp; + const struct of_device_id *match; int ret; - ret = of_property_read_string(node, "compatible", &name_tmp); - if (ret < 0) { - ts_err("get compatible failed"); - return ret; + match = of_match_node(of_match_ptr(goodix_dt_ids), node); + if (!match) { + ts_err("failed to match device tree node"); + return -EINVAL; } + ts_info("ic type is %s", match->compatible); - if (strstr(name_tmp, "9897")) { + if (strstr(match->compatible, "9897")) { ts_info("ic type is BerlinA"); ret = IC_TYPE_BERLIN_A; - } else if (strstr(name_tmp, "9966") || strstr(name_tmp, "7986")) { + } else if (strstr(match->compatible, "9966") || strstr(match->compatible, "7986")) { ts_info("ic type is BerlinB"); ret = IC_TYPE_BERLIN_B; - } else if (strstr(name_tmp, "9916")) { + } else if (strstr(match->compatible, "9916")) { ts_info("ic type is BerlinD"); ret = IC_TYPE_BERLIN_D; } else {