From patchwork Mon May 15 20:57:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 682254 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 12122C7EE25 for ; Mon, 15 May 2023 21:03:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245325AbjEOVDO (ORCPT ); Mon, 15 May 2023 17:03:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245336AbjEOVDM (ORCPT ); Mon, 15 May 2023 17:03:12 -0400 Received: from sonic312-26.consmr.mail.ir2.yahoo.com (sonic312-26.consmr.mail.ir2.yahoo.com [77.238.178.97]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0411B3AB1 for ; Mon, 15 May 2023 14:03:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1684184589; bh=Orv9xlXl2ys7vR4uDv3BL0KEya+/X55FDQeChcF+Wx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=dF2MhJ4CqN+DNtcgiesNYvI9c7QNfWYv/sIaNSVrKAC1obA9Af6O/R5S4vC62+cinn7uWC0tPoVcoqRX60KcrEfq8W9znWZcV2iQ1ejahx+APBrN0U+QdRxc2Xwj5lFamBX81w+qENwNfuSu4/sJbqNip/CGoDQPJDn/YaJDjfb22WRp2vwNoPG/uB2VtcstJe3ctCUyC4G/IAElT/2iUozagAcIuWgLRBwSxu+kvChWhvFiRTsN0lQXRSCuPCHLqH/xb0PJSGXLdi5YXLLRljdm3XUMsa7tVWG+65RXaz1YQkdo1173M7AqwTI4nhgmcoomrOW+4w9IPC5WNiH3ZA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1684184589; bh=PlXw4B/ZlsJpM1fBOzAizKqTx+HLgraJahk7CBFeWL5=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=aXxQRIy9NEiMmwA2y/SFFxu8kbmk5Fej+xSfSz8L5WaMe0eUNvfXratA3p1mAg/frU4vP44xmlM7qnwiU+U1sNlqgOWSVmxbXoBUmNbC0U5T9oPKuX2JOJedB9frD9KSikYOz+hCAzHChlDgaJ0yR0+OKsEuS64T+PrQZ115+kIVtfsUTpJ3uZlZ0UE1c29ezpIuS/mS+uU/u7SAvx4dZX4sq5Z3Hrekwxwh7fn5rW/P2wE9AtULn/OlA6A+Bx+F26s7N4ryJ2AgKXOR62f6qfXZ/c66LiLWJPYGejeohfaaK4PBTdqRYTV9LQdoOpLLn4MuLbm9VEKNL0ZndXLG4g== X-YMail-OSG: 2uk7uLcVM1nOrBPTXLT4cA1oTH8lVphI8bXzHm556tklLTUq5IRZHJf2Pxu242c OT92p2xNyeDS9w7816H01Xmh.hPulbFH3fBsZE14M9qivkS1_1oT5d2upREYsndQ6Arxx8Cn2qEt gmh7kDy0rG.1FE_7aDgU7P71yYv4sHjchSonzqZdgdD9LUbrCNqt5wTH7BGI04JA9u.yDeMY3iii uW.RtoyJtN66zLgMpAEmplzGLc_nen.NW_Ru1Jton0Lhi8zMgwwufNE4NnKeq.3zZht_enbty7dP Pn9_ZXN1rB.upi9bfZnTvvfEC0Sv5DK1x07vfb_19YCYUSuBlLmHt1IrkROy1OcmXN2JGhocg6J3 ykjSNfNj8aSX5Cvpr1UwYZrR6mb6et1wGrhiAV3ziTVGPX3LQnkBzbXfq_Lfg9eKsEqqLnoXZzta McApfsFCfy7RnVG5rGxEhSmgcumvP.oOzZA4yrDISPxsYnfKSYT3QQ8_Aau6BJV9NmGj3aAUcas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cMt9F60Fm8GOtWxBlks6RvYiers4e.5S._8jkPO4hnZ17Ft53WX0QDy6ju1IkPHlQl tY104a.BxXOTYsDJTGlbpTbMcaY3205XjJ9J.tlfUVyHGgYH4S42BroBWWnc0qOpfC_nAViIpnp1 QIZXFGeMSCr1JdQKGSm4_u.xV.gn56pFbpQXghwYKYGaTCJ32afienPGTWQkMI2icHZhMiMJSIBI JhvGGDEMwDOimP.0HpC9qDWIUoCafo5k30VGJuoyaMstX8e5K81vz10o6_YLOZl12YicO.bI_ASi BhNN7J7H9JILAl7BgcTi1VE9X1DVIUFW5sOE8YPrw2TeuPh6Xu9m78Vgv_48X9oQZyuKzxFn14G5 vKdhDVV2zpfNuudXVp3phg_KZZgKQE3julf4Nzs4sopabbpRZ0rPk_0rbQSRqmf7nzhW7WiSz3.7 67I85vA3j_vVyZUPxpQB2pBU5TYLsdS9LAks62myIYiXMFUClD5bYcSLKWNTRdcReLJWVG6RZkaJ axjxdysPXcFpv4wnFyyHc8w6MQQyIfcSl0vrQDqbH2KMC5KVZI2YL.7K1adcpqcs1bGV_KStnOW3 GocX5E1A4zHOxmi8FejM22.S.pXCM_DEuQFfKwdiIsiKmiZhpzTTS23u7uVw6JZyWbTYo_vIao0C M6YoMXMS12oeAKOX4Ik1eLaHMmRkJbPTxgKWy94ngIokBPIfZaBqiBBuG7wkzeE3ulvARJKCSasY PIjJKBTCywevNbpmFrRhf9grO1wE- X-Sonic-MF: X-Sonic-ID: 268edc4d-39d3-4099-a321-550e2d494c88 Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.ir2.yahoo.com with HTTP; Mon, 15 May 2023 21:03:09 +0000 Received: by hermes--production-ir2-7867f454fc-bgghb (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID d8cd4b5b48eaefdf4c621d749d286a70; Mon, 15 May 2023 21:03:05 +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 , Christophe Jaillet , 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 , Sebastian Reichel Subject: [PATCH v6 08/10 RESEND] power: supply: rt5033_battery: Adopt status property from charger Date: Mon, 15 May 2023 22:57:17 +0200 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: 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 Acked-by: Sebastian Reichel --- 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; }