Merge "of_batterydata: Pass battery id directly to find battery profile"

This commit is contained in:
Linux Build Service Account 2016-07-22 08:56:33 -07:00 committed by Gerrit - the friendly Code Review server
commit 10b41ef511
4 changed files with 30 additions and 41 deletions

View file

@ -1,4 +1,4 @@
/* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
/* Copyright (c) 2013-2016, 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
@ -312,32 +312,15 @@ static int64_t of_batterydata_convert_battery_id_kohm(int batt_id_uv,
struct device_node *of_batterydata_get_best_profile(
const struct device_node *batterydata_container_node,
const char *psy_name, const char *batt_type)
int batt_id_kohm, const char *batt_type)
{
struct batt_ids batt_ids;
struct device_node *node, *best_node = NULL;
struct power_supply *psy;
const char *battery_type = NULL;
union power_supply_propval ret = {0, };
int delta = 0, best_delta = 0, best_id_kohm = 0, id_range_pct,
batt_id_kohm = 0, i = 0, rc = 0, limit = 0;
i = 0, rc = 0, limit = 0;
bool in_range = false;
psy = power_supply_get_by_name(psy_name);
if (!psy) {
pr_err("%s supply not found. defer\n", psy_name);
return ERR_PTR(-EPROBE_DEFER);
}
rc = power_supply_get_property(psy, POWER_SUPPLY_PROP_RESISTANCE_ID,
&ret);
if (rc) {
pr_err("failed to retrieve resistance value rc=%d\n", rc);
return ERR_PTR(-ENOSYS);
}
batt_id_kohm = ret.intval / 1000;
/* read battery id range percentage for best profile */
rc = of_property_read_u32(batterydata_container_node,
"qcom,batt-id-range-pct", &id_range_pct);

View file

@ -4772,8 +4772,7 @@ fail:
#define BATTERY_PSY_WAIT_MS 2000
static int fg_batt_profile_init(struct fg_chip *chip)
{
int rc = 0, ret;
int len;
int rc = 0, ret, len, batt_id;
struct device_node *node = chip->pdev->dev.of_node;
struct device_node *batt_node, *profile_node;
const char *data, *batt_type_str;
@ -4802,14 +4801,16 @@ wait:
goto no_profile;
}
batt_id = get_sram_prop_now(chip, FG_DATA_BATT_ID);
batt_id /= 1000;
if (fg_debug_mask & FG_STATUS)
pr_info("battery id = %d\n",
get_sram_prop_now(chip, FG_DATA_BATT_ID));
profile_node = of_batterydata_get_best_profile(batt_node, "bms",
pr_info("battery id = %dKOhms\n", batt_id);
profile_node = of_batterydata_get_best_profile(batt_node, batt_id,
fg_batt_type);
if (!profile_node) {
pr_err("couldn't find profile handle\n");
rc = -ENODATA;
if (IS_ERR_OR_NULL(profile_node)) {
rc = PTR_ERR(profile_node);
pr_err("couldn't find profile handle %d\n", rc);
goto no_profile;
}

View file

@ -3507,19 +3507,27 @@ static int smbchg_config_chg_battery_type(struct smbchg_chip *chip)
if (chip->battery_type && !strcmp(prop.strval, chip->battery_type))
return 0;
chip->battery_type = prop.strval;
batt_node = of_parse_phandle(node, "qcom,battery-data", 0);
if (!batt_node) {
pr_smb(PR_MISC, "No batterydata available\n");
return 0;
}
profile_node = of_batterydata_get_best_profile(batt_node,
"bms", NULL);
if (!profile_node) {
pr_err("couldn't find profile handle\n");
return -EINVAL;
rc = power_supply_get_property(chip->bms_psy,
POWER_SUPPLY_PROP_RESISTANCE_ID, &prop);
if (rc < 0) {
pr_smb(PR_STATUS, "Unable to read battery-id rc=%d\n", rc);
return 0;
}
profile_node = of_batterydata_get_best_profile(batt_node,
prop.intval / 1000, NULL);
if (IS_ERR_OR_NULL(profile_node)) {
rc = PTR_ERR(profile_node);
pr_err("couldn't find profile handle %d\n", rc);
return rc;
}
chip->battery_type = prop.strval;
/* change vfloat */
rc = of_property_read_u32(profile_node, "qcom,max-voltage-uv",

View file

@ -1,4 +1,4 @@
/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
/* Copyright (c) 2013-2014, 2016 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
@ -39,10 +39,7 @@ int of_batterydata_read_data(struct device_node *container_node,
* of_batterydata_get_best_profile() - Find matching battery data device node
* @batterydata_container_node: pointer to the battery-data container device
* node containing the profile nodes.
* @psy_name: Name of the power supply which holds the
* POWER_SUPPLY_RESISTANCE_ID value to be used to match
* against the id resistances specified in the corresponding
* battery data profiles.
* @batt_id_kohm: Battery ID in KOhms for which we want to find the profile.
* @batt_type: Battery type which we want to force load the profile.
*
* This routine returns a device_node pointer to the closest match battery data
@ -50,7 +47,7 @@ int of_batterydata_read_data(struct device_node *container_node,
*/
struct device_node *of_batterydata_get_best_profile(
struct device_node *batterydata_container_node,
const char *psy_name, const char *batt_type);
int batt_id_kohm, const char *batt_type);
#else
static inline int of_batterydata_read_data(struct device_node *container_node,
struct bms_battery_data *batt_data,
@ -60,7 +57,7 @@ static inline int of_batterydata_read_data(struct device_node *container_node,
}
static inline struct device_node *of_batterydata_get_best_profile(
struct device_node *batterydata_container_node,
struct device_node *best_node, const char *psy_name)
int batt_id_kohm, const char *batt_type)
{
return -ENXIO;
}