summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-05 22:09:25 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-05 22:09:25 +0000
commit51583026f264e7597808a16aa6809fb9279eb8c4 (patch)
treeac52cfa62f5f93668b8535421097e92a199fe1e8
parentc9fa87847fde666c1031ca48fe96f0fc76d912b1 (diff)
parent96f3a0be81a0280c5a5785121dddaee8806496cd (diff)
downloadbms-51583026f264e7597808a16aa6809fb9279eb8c4.tar.gz
Merge cherrypicks of ['partner-android-review.googlesource.com/2524799'] into android13-msm-pixelwatch-5.15-eos-release.android-wear-13.0.0_r0.3android-msm-eos-5.15-tm-wear-kr3-dr-eos
Change-Id: I8e46bbb8717d0d878d766722bf4279405be2d4d7
-rw-r--r--sw5100_bms.c56
1 files changed, 44 insertions, 12 deletions
diff --git a/sw5100_bms.c b/sw5100_bms.c
index 3e6f6db..18c24bd 100644
--- a/sw5100_bms.c
+++ b/sw5100_bms.c
@@ -54,6 +54,8 @@ struct bms_dev {
u32 rradc_base;
int chg_term_voltage;
int chg_term_voltage_debounce;
+ /* Amount of SOC percentage points to offset to 0% UI SOC. */
+ int soc_shutdown_offset;
struct iio_channel *batt_therm_chan;
struct iio_channel *batt_id_chan;
struct iio_channel **iio_chan_list_qg;
@@ -818,19 +820,20 @@ static int sw5100_get_batt_present(struct bms_dev *bms)
}
/** Given a SOC percentage aka capacity we're going to scale 5-100 to 0-100. */
-static int scale_capacity(int capacity)
+static int scale_capacity(struct bms_dev const *bms, int capacity)
{
-#if defined(CAPACITY_OFFSET) && CAPACITY_OFFSET > 0 && CAPACITY_OFFSET < 100
- if (capacity > 100) {
- return 100;
- } else if (capacity >= CAPACITY_OFFSET) {
- return (((capacity - CAPACITY_OFFSET) * 100) / (100 - CAPACITY_OFFSET));
+ if (bms->soc_shutdown_offset > 0) {
+ if (capacity >= 100) {
+ return 100;
+ } else if (capacity >= bms->soc_shutdown_offset) {
+ return (((capacity - bms->soc_shutdown_offset) * 100) /
+ (100 - bms->soc_shutdown_offset));
+ } else {
+ return 0;
+ }
} else {
- return 0;
+ return capacity;
}
-#else
- return capacity;
-#endif
}
static int sw5100_psy_get_property(struct power_supply *psy,
@@ -940,12 +943,12 @@ static int sw5100_psy_get_property(struct power_supply *psy,
case GBMS_PROP_CAPACITY_RAW:
rc = sw5100_get_prop_from_bms(bms, SW5100_QBG_CAPACITY, &ivalue);
if (rc == 0)
- pval->intval = (scale_capacity(ivalue) << 8);
+ pval->intval = (scale_capacity(bms, ivalue) << 8);
break;
case POWER_SUPPLY_PROP_CAPACITY:
rc = sw5100_get_prop_from_bms(bms, SW5100_QBG_CAPACITY, &ivalue);
if (rc == 0)
- pval->intval = scale_capacity(ivalue);
+ pval->intval = scale_capacity(bms, ivalue);
break;
case POWER_SUPPLY_PROP_CYCLE_COUNT:
rc = sw5100_get_prop_from_bms(bms, SW5100_QBG_CYCLE_COUNT, &ivalue);
@@ -1075,6 +1078,27 @@ static int sw5100_charge_pause(struct bms_dev *bms, bool pause)
return rc;
}
+static ssize_t soc_shutdown_offset_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct power_supply *psy = container_of(dev, struct power_supply, dev);
+ struct bms_dev *bms = power_supply_get_drvdata(psy);
+
+ sscanf(buf, "%d", &bms->soc_shutdown_offset);
+ return count;
+}
+
+static ssize_t soc_shutdown_offset_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ struct power_supply *psy = container_of(dev, struct power_supply, dev);
+ struct bms_dev *bms = power_supply_get_drvdata(psy);
+
+ return scnprintf(buf, PAGE_SIZE, "%d\n", bms->soc_shutdown_offset);
+}
+
+static const DEVICE_ATTR_RW(soc_shutdown_offset);
+
static int sw5100_psy_set_property(struct power_supply *psy,
enum power_supply_property psp,
const union power_supply_propval *pval)
@@ -1278,6 +1302,10 @@ static int sw5100_parse_dt(struct bms_dev *bms)
sw5100_psy_desc.name =
devm_kstrdup(bms->dev, psy_name, GFP_KERNEL);
+ ret = of_property_read_u32(node, "google,soc_shutdown_offset", &bms->soc_shutdown_offset);
+ if (ret < 0)
+ bms->soc_shutdown_offset = 0;
+
if (sw5100_psy_desc.name == NULL)
return -EINVAL;
@@ -1343,6 +1371,10 @@ static int bms_probe(struct platform_device *pdev)
goto exit;
}
+ rc = device_create_file(&bms->psy->dev, &dev_attr_soc_shutdown_offset);
+ if (rc < 0)
+ dev_err(&bms->psy->dev, "Failed to create soc scaling offset for shutdown\n");
+
iio_list = sw5100_get_ext_channels(bms->dev, sw5100_qbg_ext_iio_chan,
ARRAY_SIZE(sw5100_qbg_ext_iio_chan));
if (!IS_ERR(iio_list))