From f2c049533f07827c7f11f41c8dfb2db749bdc1db Mon Sep 17 00:00:00 2001 From: jixj Date: Tue, 13 Oct 2020 14:03:47 +0800 Subject: [PATCH] mmi_info: export API for dynamically match mmi device After flashing GKI, https://gerrit.mot.com/#/c/1439246/ is not available. Export API to match "mmi,status" rules, the other modules can use this API to check if driver is available at the begining of probe() function. Change-Id: I58413e071e32b82037c72c688a7bbbadce28007c Reviewed-on: https://gerrit.mot.com/1772580 SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Reviewed-by: Konstantin Makariev Submit-Approved: Jira Key --- drivers/mmi_info/mmi_info_main.c | 72 ++++++++++++++++++++++++++++++++ include/linux/mmi_device.h | 18 ++++++++ 2 files changed, 90 insertions(+) create mode 100644 include/linux/mmi_device.h diff --git a/drivers/mmi_info/mmi_info_main.c b/drivers/mmi_info/mmi_info_main.c index 0dcfe678b536..c80736cbcec2 100644 --- a/drivers/mmi_info/mmi_info_main.c +++ b/drivers/mmi_info/mmi_info_main.c @@ -16,11 +16,83 @@ #include #include #include +#include #include "mmi_info.h" struct mmi_chosen_info mmi_chosen_data; static char *bootargs_str; +/** + * mmi_device_is_available - check if a device is available for use + * + * @device: Node to check for availability, with locks already held + * + * Returns true if the status property + * -- is absent, + * -- refers to another property using string list as following + * mmi,status = , , [,] [, ...]; + * and at least one in the list of values matches + * value of //. + * Partial matches accepted when "contains" provided. + * false otherwise + */ +bool mmi_device_is_available(struct device_node *np) +{ + bool found; + int len, operation; + const char *path, *mmi_dts; + const char *mmi_dts_val, *val; + struct property *prop; + struct device_node *mmi_np; + + if (np == NULL) + return true; + + prop = of_find_property(np, "mmi,status", &len); + if (prop == NULL || len < 0) { + return true; + } + path = prop->value; + + mmi_np = of_find_node_by_path(path); + if (mmi_np == NULL) + return false; + + mmi_dts = of_prop_next_string(prop, path); + if (mmi_dts == NULL) + return false; + + mmi_dts_val = of_get_property(mmi_np, mmi_dts, &len); + if (mmi_dts_val == NULL || len <= 0) + return false; + + val = mmi_dts; + operation = 0; + found = false; + while ((val = of_prop_next_string(prop, val))) { + if (val == NULL) + return false; + + if (!operation) { + operation++; + if (!strcmp(val, "contains")) { + operation++; + continue; + } + } + if (operation == 1) { + if (!strcmp(val, mmi_dts_val)) + found = true; + } else if (strstr(mmi_dts_val, val)) { + found = true; + } + if (found) + return true; + } + return false; +} +EXPORT_SYMBOL(mmi_device_is_available); + int mmi_get_bootarg(char *key, char **value) { const char *bootargs_tmp = NULL; diff --git a/include/linux/mmi_device.h b/include/linux/mmi_device.h new file mode 100644 index 000000000000..4f97dd8a7d07 --- /dev/null +++ b/include/linux/mmi_device.h @@ -0,0 +1,18 @@ +/* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef __MMI_DEVICE_H_INCLUDED +#define __MMI_DEVICE_H_INCLUDED + +bool mmi_device_is_available(struct device_node *np); + +#endif /* __MMI_DEVICE_H_INCLUDED */