From patchwork Sun May 14 12:31:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 682271 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F2FDC7EE24 for ; Sun, 14 May 2023 12:37:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235831AbjENMha (ORCPT ); Sun, 14 May 2023 08:37:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233993AbjENMh3 (ORCPT ); Sun, 14 May 2023 08:37:29 -0400 Received: from sonic314-19.consmr.mail.ir2.yahoo.com (sonic314-19.consmr.mail.ir2.yahoo.com [77.238.177.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9060D19A3 for ; Sun, 14 May 2023 05:37:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1684067845; bh=iR6f3XRVOHcEpdjcnFCif4nNa1shR7J/nAlLWRT5R4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=aNDwZkDhIJzo4X4lCijZaF803UlbasjNKxdPtFrPJjSswTHmICKbz4nGPtmZeMGWBDQfbp+luEfFb6rjlqb59sKKJsLfhCrm4GFuF4shK6rNeIBY751vV5L27gukt7acQyNjIfE7ThqHjH9zs56cE3zw2LHv4zjpox+M5eIPbBTJ0baEFLQA1n/Qd+ITibYbDZ8FJyIKGGxK3oaTds9jXKvRKu7LZoHufuXwhitmHZmAkCIj5lDXiMO9uTGIyneRPKd4jma+H15ZGzUazW8fuHHamtlKD4uhd+SohMW33rI7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Hi.K .81.aHPLJ7twgIPn6d..4XR5nzpzW.A6J3YH966piemWF7RZnqlUGB45a3XyFP6OBHau41kQ2Wz6 jkSqLJvgchRpj9EO3DWBiacNaTLoRuZtmLYxro8kcIE5uYuVUX5luHV0mHD6T3ZyCo3jOziCyvsA WvPb1McXLgUr.0heWZ6f.pIMrFHUiepyaHVMFxu0YSEhUj3LLRyRapbzv1yL0zSF03b62VC48oQ8 PIzQup1w9DOWDIaEjyPR0jeFZvA8AufZKyB4vvIz1srSkv0kvqhpZozqmlD4hu.jpXuzZOcEWojm k.pI10d0VT7lNXtzG_xCSkuAV34QBKdZ3SQNL64D_CxOakue3ZtuVHHFkTE2vZZQmnilr8qn.ljV dDu1JXdXWjJcPCDXN5xIuxg1qgzCtlTlrBxfR7t6auJJGk0lt.DyHjhl3e7cKItg9UwXdhq8l6Mw _DfwK_gTXqH.UOom6ruRjHYcQxQXKFCh0yfad.0Ut6qzgNzK0ve1LDMzgvHJWX7e6gaKeyNTS6m8 5dadqfo2jlQhuMe9_Q5sB5_FrtVMiLauXCT46kDyintoH_.b4047XYAgPfKj697O8cVHKam0CBRP 7zWVeTUKXIm1FKg2XjXdHRziInEnytwPYUFnwcWQfgnRwidhmqeMju3pYMB1Rin6ALl3jMn8004p KcV_EFqxSYwTxa7di1P6wehSrapEXM2r17Rz8Z5iuZKjOSFKl_ie41GZuqBwGFGkotQMGMoKvZeB CXls_ki6QIi98d3w27Ns9tXyVu.ih5w-- X-Sonic-MF: X-Sonic-ID: 877ba4c0-0451-46bb-a1c2-970c7ffcb540 Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ir2.yahoo.com with HTTP; Sun, 14 May 2023 12:37:25 +0000 Received: by hermes--production-ir2-7867f454fc-tvsct (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID ec262f708c8ca7d1990bed607fb68ca2; Sun, 14 May 2023 12:37:22 +0000 (UTC) From: Jakob Hauser To: Sebastian Reichel , Lee Jones , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski Cc: Beomho Seo , Chanwoo Choi , Stephan Gerhold , Raymond Hackley , Pavel Machek , Axel Lin , ChiYuan Huang , Linus Walleij , Henrik Grimler , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v5 08/10] power: supply: rt5033_battery: Adopt status property from charger Date: Sun, 14 May 2023 14:31:28 +0200 Message-Id: <20230514123130.41172-9-jahau@rocketmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230514123130.41172-1-jahau@rocketmail.com> References: <20230514123130.41172-1-jahau@rocketmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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 --- drivers/power/supply/rt5033_battery.c | 29 +++++++++++++++++++++------ 1 file 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; }