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 <kmakariev@motorola.com>
Submit-Approved: Jira Key
This commit is contained in:
jixj 2022-05-17 15:55:12 +08:00 • committed by Xiaojun Ji
commit 2e56ea884d
4 changed files with 19 additions and 15 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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);

View file

@ -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 */