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 <kmakariev@motorola.com>
Submit-Approved: Jira Key
This commit is contained in:
jixj 2020-10-13 14:03:47 +08:00 • committed by Xiaojun Ji
commit f2c049533f
2 changed files with 90 additions and 0 deletions

View file

@ -16,11 +16,83 @@
#include <linux/of_platform.h>
#include <linux/ctype.h>
#include <linux/slab.h>
#include <linux/mmi_device.h>
#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 = <path>, <okay property>, [<contains>,] <value1>[, <value2>...];
* and at least one <value> in the list of values matches
* value of /<path>/<okay property>.
* 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;

View file

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