summaryrefslogtreecommitdiff
path: root/drivers/power/supply/rt5033_battery.c
diff options
context:
space:
mode:
authorJakob Hauser <jahau@rocketmail.com>2023-05-15 23:57:17 +0300
committerLee Jones <lee@kernel.org>2023-06-08 20:17:50 +0300
commit4ed21f06a913f79850d8c937c15fda03dde34512 (patch)
tree7e2f70930172dbbbc92d4ce4f9d4ea2fd76722e3 /drivers/power/supply/rt5033_battery.c
parent49b435908b2aeb0f3a8a5256256019594a5adc1c (diff)
downloadlinux-4ed21f06a913f79850d8c937c15fda03dde34512.tar.xz
power: supply: rt5033_battery: Adopt status property from charger
The rt5033-battery fuelgauge can't get a status by itself. The rt5033-charger can, let's get this value. To get the charger as a "supplier" from the devicetree, the "of_node" needs to be initiated. Additionally, in the probe function replace dev_err() with dev_err_probe(), this will avoid printing an error for -EPROBE_DEFER when the battery driver probes before the charger driver. Signed-off-by: Jakob Hauser <jahau@rocketmail.com> Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Lee Jones <lee@kernel.org> Link: https://lore.kernel.org/r/a2015d257b145108a3ecdf107a3040362c887fc5.1684182964.git.jahau@rocketmail.com
Diffstat (limited to 'drivers/power/supply/rt5033_battery.c')
-rw-r--r--drivers/power/supply/rt5033_battery.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/drivers/power/supply/rt5033_battery.c b/drivers/power/supply/rt5033_battery.c
index 91e1efd81f69..94d2dea7ef5e 100644
--- a/drivers/power/supply/rt5033_battery.c
+++ b/drivers/power/supply/rt5033_battery.c
@@ -19,6 +19,21 @@ struct rt5033_battery {
struct power_supply *psy;
};
+static int rt5033_battery_get_status(struct i2c_client *client)
+{
+ struct rt5033_battery *battery = i2c_get_clientdata(client);
+ union power_supply_propval val;
+ int ret;
+
+ ret = power_supply_get_property_from_supplier(battery->psy,
+ POWER_SUPPLY_PROP_STATUS,
+ &val);
+ if (ret)
+ val.intval = POWER_SUPPLY_STATUS_UNKNOWN;
+
+ return val.intval;
+}
+
static int rt5033_battery_get_capacity(struct i2c_client *client)
{
struct rt5033_battery *battery = i2c_get_clientdata(client);
@@ -91,6 +106,9 @@ static int rt5033_battery_get_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_CAPACITY:
val->intval = rt5033_battery_get_capacity(battery->client);
break;
+ case POWER_SUPPLY_PROP_STATUS:
+ val->intval = rt5033_battery_get_status(battery->client);
+ break;
default:
return -EINVAL;
}
@@ -103,6 +121,7 @@ static enum power_supply_property rt5033_battery_props[] = {
POWER_SUPPLY_PROP_VOLTAGE_OCV,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_CAPACITY,
+ POWER_SUPPLY_PROP_STATUS,
};
static const struct regmap_config rt5033_battery_regmap_config = {
@@ -124,7 +143,6 @@ static int rt5033_battery_probe(struct i2c_client *client)
struct i2c_adapter *adapter = client->adapter;
struct power_supply_config psy_cfg = {};
struct rt5033_battery *battery;
- u32 ret;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
return -EIO;
@@ -142,15 +160,14 @@ static int rt5033_battery_probe(struct i2c_client *client)
}
i2c_set_clientdata(client, battery);
+ psy_cfg.of_node = client->dev.of_node;
psy_cfg.drv_data = battery;
battery->psy = power_supply_register(&client->dev,
&rt5033_battery_desc, &psy_cfg);
- if (IS_ERR(battery->psy)) {
- dev_err(&client->dev, "Failed to register power supply\n");
- ret = PTR_ERR(battery->psy);
- return ret;
- }
+ if (IS_ERR(battery->psy))
+ return dev_err_probe(&client->dev, PTR_ERR(battery->psy),
+ "Failed to register power supply\n");
return 0;
}