From 2e56ea884d63f80e5bdde3e9f28346c2f6e4bf9e Mon Sep 17 00:00:00 2001 From: jixj Date: Tue, 17 May 2022 15:55:12 +0800 Subject: [PATCH] Integrate mmi_device_is_available() into mmi_check_dynamic_device_node() mmi_check_dynamic_device_node() uses of_find_node_by_path() to get device node so that mmi_device_is_available() can use this node to find where is "mmi,status".but need use of_node_put() to put this node in there drivers. So move "mmi_device_is_available()" into "mmi_check_dynamic_device_node()" and put the device node at the end. Change-Id: Id42e73b844ef6928ebea673dcd7f9c57c8804f8b Reviewed-on: https://gerrit.mot.com/2271017 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Konstantin Makariev Submit-Approved: Jira Key --- .../goodix_berlin_mmi/goodix_brl_i2c.c | 5 +--- drivers/input/touchscreen/stmicro_mmi/fts.c | 4 +--- drivers/mmi_info/mmi_info_main.c | 23 +++++++++++++------ include/linux/mmi_device.h | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/drivers/input/touchscreen/goodix_berlin_mmi/goodix_brl_i2c.c b/drivers/input/touchscreen/goodix_berlin_mmi/goodix_brl_i2c.c index 5118e341d8ec..85c340be17f8 100644 --- a/drivers/input/touchscreen/goodix_berlin_mmi/goodix_brl_i2c.c +++ b/drivers/input/touchscreen/goodix_berlin_mmi/goodix_brl_i2c.c @@ -263,11 +263,8 @@ static struct i2c_driver goodix_i2c_driver = { int goodix_i2c_bus_init(void) { - struct device_node *node; - ts_info("Goodix i2c driver init"); - node = mmi_check_dynamic_device_node("goodix_ts_i2c"); - if (!node || mmi_device_is_available(node)) + if (mmi_check_dynamic_device_node("goodix_ts_i2c")) return i2c_add_driver(&goodix_i2c_driver); return -ENODEV; } diff --git a/drivers/input/touchscreen/stmicro_mmi/fts.c b/drivers/input/touchscreen/stmicro_mmi/fts.c index c0acecc028f8..c805eaf140e9 100644 --- a/drivers/input/touchscreen/stmicro_mmi/fts.c +++ b/drivers/input/touchscreen/stmicro_mmi/fts.c @@ -4551,9 +4551,7 @@ static struct spi_driver fts_spi_driver = { static int __init fts_driver_init(void) { #ifdef I2C_INTERFACE - struct device_node *node; - node = mmi_check_dynamic_device_node("st_fts"); - if (!node || mmi_device_is_available(node)) + if (mmi_check_dynamic_device_node("st_fts")) return i2c_add_driver(&fts_i2c_driver); return -ENODEV; #else diff --git a/drivers/mmi_info/mmi_info_main.c b/drivers/mmi_info/mmi_info_main.c index ca44295b483f..eac49121ff4b 100644 --- a/drivers/mmi_info/mmi_info_main.c +++ b/drivers/mmi_info/mmi_info_main.c @@ -94,33 +94,42 @@ bool mmi_device_is_available(struct device_node *np) } EXPORT_SYMBOL(mmi_device_is_available); -struct device_node *mmi_check_dynamic_device_node(char *dev_name) +bool mmi_check_dynamic_device_node(char *dev_name) { struct property *prop; - struct device_node *node, *dst_node; + struct device_node *node, *dst_node = NULL; int len; char *val = NULL; + bool result = true; node = of_find_node_by_path("/chosen"); if (node == NULL) - return NULL; + goto out; prop = of_find_property(node, "mmi,dynamic_devices", &len); of_node_put(node); if (prop == NULL || len < 0) { pr_err("%s: cannot find mmi,dynamic_devices property\n", __func__); - return NULL; + goto out; } while ((val = (char *)of_prop_next_string(prop, val))) { if (strstr(val, dev_name)) { pr_info("%s: find matched dev name string %s\n", __func__, val); dst_node = of_find_node_by_path(val); - return dst_node; + break; } } - pr_err("%s: cannot find any node with dev_name %s\n", __func__, dev_name); - return NULL; + + if (dst_node == NULL) { + pr_err("%s: cannot find any node with dev_name %s\n", __func__, dev_name); + goto out; + } + + result = mmi_device_is_available(dst_node); + of_node_put(dst_node); +out: + return result; } EXPORT_SYMBOL(mmi_check_dynamic_device_node); diff --git a/include/linux/mmi_device.h b/include/linux/mmi_device.h index 5de81a954a4b..97dda682fc87 100644 --- a/include/linux/mmi_device.h +++ b/include/linux/mmi_device.h @@ -14,6 +14,6 @@ #define __MMI_DEVICE_H_INCLUDED bool mmi_device_is_available(struct device_node *np); -struct device_node *mmi_check_dynamic_device_node(char *dev_name); +bool mmi_check_dynamic_device_node(char *dev_name); #endif /* __MMI_DEVICE_H_INCLUDED */