From patchwork Sun Jun 8 20:40:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 895086 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5FCA18CC1C for ; Sun, 8 Jun 2025 20:40:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415217; cv=none; b=O2ejUlrDB4zmAXWxcJmFCO/GNXXsKYe6UeLrDOH3/mEsGlS/Tg2TvdFvlTJGLpWyGYAr92gY2hHbeid3ZhLUn7JRtg1t5yNKVyBCrkwRi/8wBmvN+bjZisz/Djo9d9TDkJUAMSEc/fZYhgdefjmCOFtpkQKpziwpXCU+0DFHwdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415217; c=relaxed/simple; bh=6k84NDF/UFSgdkBu89qk4s4Ny/cAH9w+gjDgw6Nkv24=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OlqlgHmb3TeiWjjd9ROHDcbLisvSeUQ/xec91cJdJShMbMbsqxku9EddyV9ay/wxxmB3gYr7vlvcoInX/BFxKE7PBSLVy34S1qM1xPJslJno++iGkU42RFksGQcG9z3nfrdoLvSaXPOHwog8mQI9joBkhULzCP8SMxBDcM3VGZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S9l3PJ3G; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S9l3PJ3G" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7775C4CEF3; Sun, 8 Jun 2025 20:40:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749415216; bh=6k84NDF/UFSgdkBu89qk4s4Ny/cAH9w+gjDgw6Nkv24=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S9l3PJ3GyTDZ5a/F+rDfnll9tQHq1MDW6p6zlKIaAdfTIGrO1kjIcH7td+O/6UNco 3+Ern4bJUi/UuLLnH03eGomEHnTfTs1Ke/YPbt37X2e+lVivpJi5XgxSofuU7Cqeiz Q70W2twBM3bTaoBncyaRGWgSo6IUfkyvSw11cRZbQxwE+nGpCm4c6H3RErfXYMGgL3 0KQhS5Q1VxlxliUb7gU6O30FbL94wrAMSnBygjp/WWu9NU1hsmz+yZQ3t6Tptj9vJg SwUi8orWDDt//PRCUvoqCPJWPuw7imgIisFgBKtwOvl3WV1bPSSHNEW/HJnf0zJJ3H QwOG7zcs4Ma4A== From: Hans de Goede To: Sebastian Reichel Cc: Hans de Goede , Mark Brown , AngeloGioacchino Del Regno , Linus Walleij , linux-pm@vger.kernel.org, Sebastian Reichel Subject: [PATCH 01/10] regulator: act8865-regulator: switch psy_cfg from of_node to fwnode Date: Sun, 8 Jun 2025 22:40:01 +0200 Message-ID: <20250608204010.37482-2-hansg@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250608204010.37482-1-hansg@kernel.org> References: <20250608204010.37482-1-hansg@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Sebastian Reichel In order to remove .of_node from the power_supply_config struct, use .fwnode instead. Signed-off-by: Sebastian Reichel Link: https://lore.kernel.org/r/20250430-psy-core-convert-to-fwnode-v2-1-f9643b958677@collabora.com Reviewed-by: Hans de Goede Signed-off-by: Hans de Goede --- drivers/regulator/act8865-regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c index 0457af23c55a..b2a6ddc6f56d 100644 --- a/drivers/regulator/act8865-regulator.c +++ b/drivers/regulator/act8865-regulator.c @@ -643,7 +643,7 @@ static int act8600_charger_probe(struct device *dev, struct regmap *regmap) struct power_supply *charger; struct power_supply_config cfg = { .drv_data = regmap, - .of_node = dev->of_node, + .fwnode = dev_fwnode(dev), }; charger = devm_power_supply_register(dev, &act8600_charger_desc, &cfg); From patchwork Sun Jun 8 20:40:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 894874 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C7B518CC1C for ; Sun, 8 Jun 2025 20:40:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415218; cv=none; b=iEMopf0UpxuPLpWRyUdDGxPa9ucMeIIaWvtqFKYlnMS2LVFamGNhb+YRojFDo7VgF4rBJtTw7NK7zu4lyEqul2bymQpdPHID+0V39LiWV6bRLQx3EhGKRy1NZ67cKmDGxEQErXJxta/W8DskatXGdD4xZfJ/QQ1jwCkYO4lATSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415218; c=relaxed/simple; bh=rdDVrZgNjdEGWhzWL2tEJ8faCkw6O/RR8FTXM1XB5n8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MtgEbYyk4LhZsoNEbFcb7uIz9RetsWbwhJDcvSNvJSOxXrE39wvNTr1O02NTZkjhie5ChpzQxPtZ67sGUa1f208OiyCszxWvzFhaDUZ6AnTKtlICTYrqED3COSPjcGler7HDQTfYgTryA/8WDlXL4h0P3XOh9arzCk4yBgWVKgo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SHcIhLPy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SHcIhLPy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB6A3C4CEF1; Sun, 8 Jun 2025 20:40:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749415218; bh=rdDVrZgNjdEGWhzWL2tEJ8faCkw6O/RR8FTXM1XB5n8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SHcIhLPyTGvh/9Dt1EDwNJM/WzgAXlKtQ/qr1AYRpGMU8VYEUociSYhINIiOCDJOz 0GFbrXaPo5c7c0XTIkpMQfbqp+T7Yq2lckFff5N73ebM7aj8EJN2R039spe37fysAc oICH5pbfDFjIXlCwtB/UfqCOtZ1ZgHEPRsP7Q8Ar0TuUFCsiBImPOo5dZDpqCryvJF KZFhQK/+7iGrXvaRFVWBggHdEsI0dIiPly/z3zsk+TbMOYTnBJ+N9zYTbbQ4sgLTPL YPdZZ2eSltFK7iHejDWUK83mjDqlpRl1v2nIVN8xgYUyRXO/apmnLe6Vtk/0gWXmjq uiKBhbqaN2G6Q== From: Hans de Goede To: Sebastian Reichel Cc: Hans de Goede , Mark Brown , AngeloGioacchino Del Regno , Linus Walleij , linux-pm@vger.kernel.org, Sebastian Reichel Subject: [PATCH 02/10] power: supply: core: remove of_node from power_supply_config Date: Sun, 8 Jun 2025 22:40:02 +0200 Message-ID: <20250608204010.37482-3-hansg@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250608204010.37482-1-hansg@kernel.org> References: <20250608204010.37482-1-hansg@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Sebastian Reichel All drivers have been migrated from .of_node to .fwnode, so let's kill the former. Reviewed-by: AngeloGioacchino Del Regno Signed-off-by: Sebastian Reichel Link: https://lore.kernel.org/r/20250430-psy-core-convert-to-fwnode-v2-2-f9643b958677@collabora.com Reviewed-by: Hans de Goede Signed-off-by: Hans de Goede --- drivers/power/supply/power_supply_core.c | 3 +-- include/linux/power_supply.h | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 33a5bfce4604..89947f1fe610 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -1529,10 +1529,9 @@ __power_supply_register(struct device *parent, dev_set_drvdata(dev, psy); psy->desc = desc; if (cfg) { + device_set_node(dev, cfg->fwnode); dev->groups = cfg->attr_grp; psy->drv_data = cfg->drv_data; - dev->of_node = - cfg->fwnode ? to_of_node(cfg->fwnode) : cfg->of_node; psy->supplied_to = cfg->supplied_to; psy->num_supplicants = cfg->num_supplicants; } diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 03786c8c2efe..3e52883f866b 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -232,7 +232,6 @@ struct power_supply; /* Run-time specific power supply configuration */ struct power_supply_config { - struct device_node *of_node; struct fwnode_handle *fwnode; /* Driver private data */ From patchwork Sun Jun 8 20:40:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 895085 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AE1C18CC1C for ; Sun, 8 Jun 2025 20:40:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415222; cv=none; b=Gm+LeTxMPCj5mhyDfDO5A3dcyjE4ZkH+VnCQTfO7LJMIw0Nt0eFAnzSpzi/d0RvnQyEfhVVsylLfaS0LBUYvvZG3pw4GnK51Q6WxkEk8skSy03KMhPnbam+V1TFx1RdHmVFyOKmP7BWio5QWhYjI1UcIZEt+vHpTf1lzytSqnUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415222; c=relaxed/simple; bh=yHuzgDhKmYHqcVVXHvrFIheirJD1TcGoM1Q2eK6mQ0c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o054pmpGrG5PbI97lb/ozh9YowzZsv4O0Z8qXHpUe2awhlTH6QiZi5NCz9O9UM2IPR4pwI1ZVBoYxXKLMIBlLl+O6Xgt91Pmty678bO1uMdL2ESpEMQ4QMdQRnD+egVmGaiOgV42U5wJknyuFSVT0IfsS/aWG0fzNb0Yr0tcsRY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pzVoUQ1O; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pzVoUQ1O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECAB6C4CEEE; Sun, 8 Jun 2025 20:40:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749415220; bh=yHuzgDhKmYHqcVVXHvrFIheirJD1TcGoM1Q2eK6mQ0c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pzVoUQ1OLkcaqRYfeeklALeyW05aLAfGuywcphI+4OrwQMLFVkt59IJ7D2+yEizer SmjB+wKqB9xEcnS47bYAgmvLS0a9rstupUUTI0ZD+Xn4Vp+9opcB+h8QCy5EcIrKDr u0hsBR38EhlNE2SHWpr+whPoFv+LFREGDHnGcdlG2ICWGBkGmbqKt5K23tSMaZpgYd OhZmaxroP5k6u5fOjf+/AoWzaJ+4krxiQbez6Rh7IGgPCEN7H+20fBFZBSP3aXuzpI IjNxJQw1W+aGiJYZclFgvBJYOOE/rPMb7Lq2DUCpuSLeqp9Xc//u8VisjDbZVSg9F4 U/FkJRhiBH35Q== From: Hans de Goede To: Sebastian Reichel Cc: Hans de Goede , Mark Brown , AngeloGioacchino Del Regno , Linus Walleij , linux-pm@vger.kernel.org, Sebastian Reichel Subject: [PATCH 03/10] power: supply: core: battery-info: fully switch to fwnode Date: Sun, 8 Jun 2025 22:40:03 +0200 Message-ID: <20250608204010.37482-4-hansg@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250608204010.37482-1-hansg@kernel.org> References: <20250608204010.37482-1-hansg@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Sebastian Reichel Also use fwnode based parsing for "ocv-capacity-celsius" and "resistance-temp-table", so that any DT specific bits are removed from the power-supply core. Reviewed-by: AngeloGioacchino Del Regno Signed-off-by: Sebastian Reichel Link: https://lore.kernel.org/r/20250430-psy-core-convert-to-fwnode-v2-3-f9643b958677@collabora.com Signed-off-by: Hans de Goede --- drivers/power/supply/power_supply_core.c | 109 +++++++++++++---------- 1 file changed, 63 insertions(+), 46 deletions(-) diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 89947f1fe610..a8d1fe66e248 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -585,32 +585,19 @@ int power_supply_get_battery_info(struct power_supply *psy, { struct power_supply_resistance_temp_table *resist_table; struct power_supply_battery_info *info; - struct device_node *battery_np = NULL; - struct fwnode_reference_args args; - struct fwnode_handle *fwnode = NULL; + struct fwnode_handle *srcnode, *fwnode; const char *value; - int err, len, index; - const __be32 *list; + int err, len, index, proplen; + u32 *propdata; u32 min_max[2]; - if (psy->dev.of_node) { - battery_np = of_parse_phandle(psy->dev.of_node, "monitored-battery", 0); - if (!battery_np) - return -ENODEV; + srcnode = dev_fwnode(&psy->dev); + if (!srcnode && psy->dev.parent) + srcnode = dev_fwnode(psy->dev.parent); - fwnode = fwnode_handle_get(of_fwnode_handle(battery_np)); - } else if (psy->dev.parent) { - err = fwnode_property_get_reference_args( - dev_fwnode(psy->dev.parent), - "monitored-battery", NULL, 0, 0, &args); - if (err) - return err; - - fwnode = args.fwnode; - } - - if (!fwnode) - return -ENOENT; + fwnode = fwnode_find_reference(srcnode, "monitored-battery", 0); + if (IS_ERR(fwnode)) + return PTR_ERR(fwnode); err = fwnode_property_read_string(fwnode, "compatible", &value); if (err) @@ -740,15 +727,7 @@ int power_supply_get_battery_info(struct power_supply *psy, info->temp_max = min_max[1]; } - /* - * The below code uses raw of-data parsing to parse - * /schemas/types.yaml#/definitions/uint32-matrix - * data, so for now this is only support with of. - */ - if (!battery_np) - goto out_ret_pointer; - - len = of_property_count_u32_elems(battery_np, "ocv-capacity-celsius"); + len = fwnode_property_count_u32(fwnode, "ocv-capacity-celsius"); if (len < 0 && len != -EINVAL) { err = len; goto out_put_node; @@ -757,13 +736,13 @@ int power_supply_get_battery_info(struct power_supply *psy, err = -EINVAL; goto out_put_node; } else if (len > 0) { - of_property_read_u32_array(battery_np, "ocv-capacity-celsius", + fwnode_property_read_u32_array(fwnode, "ocv-capacity-celsius", info->ocv_temp, len); } for (index = 0; index < len; index++) { struct power_supply_battery_ocv_table *table; - int i, tab_len, size; + int i, tab_len; char *propname __free(kfree) = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index); @@ -772,60 +751,98 @@ int power_supply_get_battery_info(struct power_supply *psy, err = -ENOMEM; goto out_put_node; } - list = of_get_property(battery_np, propname, &size); - if (!list || !size) { + proplen = fwnode_property_count_u32(fwnode, propname); + if (proplen < 0 || proplen % 2 != 0) { dev_err(&psy->dev, "failed to get %s\n", propname); power_supply_put_battery_info(psy, info); err = -EINVAL; goto out_put_node; } + propdata = kcalloc(proplen, sizeof(*propdata), GFP_KERNEL); + if (!propdata) { + kfree(propname); + power_supply_put_battery_info(psy, info); + err = -EINVAL; + goto out_put_node; + } + err = fwnode_property_read_u32_array(fwnode, propname, propdata, proplen); + if (err < 0) { + dev_err(&psy->dev, "failed to get %s\n", propname); + kfree(propname); + kfree(propdata); + power_supply_put_battery_info(psy, info); + goto out_put_node; + } - tab_len = size / (2 * sizeof(__be32)); + tab_len = proplen / 2; info->ocv_table_size[index] = tab_len; info->ocv_table[index] = table = devm_kcalloc(&psy->dev, tab_len, sizeof(*table), GFP_KERNEL); if (!info->ocv_table[index]) { + kfree(propdata); power_supply_put_battery_info(psy, info); err = -ENOMEM; goto out_put_node; } for (i = 0; i < tab_len; i++) { - table[i].ocv = be32_to_cpu(*list); - list++; - table[i].capacity = be32_to_cpu(*list); - list++; + table[i].ocv = propdata[i*2]; + table[i].capacity = propdata[i*2+1]; } + + kfree(propdata); } - list = of_get_property(battery_np, "resistance-temp-table", &len); - if (!list || !len) + proplen = fwnode_property_count_u32(fwnode, "resistance-temp-table"); + if (proplen < 0 || proplen % 2 != 0) { + power_supply_put_battery_info(psy, info); + err = -ENOMEM; goto out_ret_pointer; + } else if (proplen == 0) { + goto out_ret_pointer; + } - info->resist_table_size = len / (2 * sizeof(__be32)); + propdata = kcalloc(proplen, sizeof(*propdata), GFP_KERNEL); + if (!propdata) { + power_supply_put_battery_info(psy, info); + err = -ENOMEM; + goto out_ret_pointer; + } + + err = fwnode_property_read_u32_array(fwnode, "resistance-temp-table", + propdata, proplen); + if (err < 0) { + kfree(propdata); + power_supply_put_battery_info(psy, info); + goto out_put_node; + } + + info->resist_table_size = proplen / 2; info->resist_table = resist_table = devm_kcalloc(&psy->dev, info->resist_table_size, sizeof(*resist_table), GFP_KERNEL); if (!info->resist_table) { + kfree(propdata); power_supply_put_battery_info(psy, info); err = -ENOMEM; goto out_put_node; } for (index = 0; index < info->resist_table_size; index++) { - resist_table[index].temp = be32_to_cpu(*list++); - resist_table[index].resistance = be32_to_cpu(*list++); + resist_table[index].temp = propdata[index*2]; + resist_table[index].resistance = propdata[index*2+1]; } + kfree(propdata); + out_ret_pointer: /* Finally return the whole thing */ *info_out = info; out_put_node: fwnode_handle_put(fwnode); - of_node_put(battery_np); return err; } EXPORT_SYMBOL_GPL(power_supply_get_battery_info); From patchwork Sun Jun 8 20:40:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 894873 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3EB318CC1C for ; Sun, 8 Jun 2025 20:40:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415222; cv=none; b=F4kZ3aax25cXjXeDEpmDU2gquHYYE/0B6/zpZutFPkADL4Od5EsFqjMOYfzhkPgS48oRnll6gmGB6GQ0Wm6pohnzd2YD7MPE/sVhiNGgzc97edJxDEAAL7s18nqFlXSE0Vmv7pbFUfKmLUKtMKRqz593BXYtXT63g6CUjn6KlHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415222; c=relaxed/simple; bh=vuKnESaBbThs2Ul53Pi+Hd5SXFdYZONrY95yvzz06xI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HkxmSuZuhH7yIVBgJfUNffpSUex6LpgqS9HvcQZnzVZD+PXShzlu/7L70b+F0IuIQD/ZdChuVWddGiQtXe7Ze2br4h1QUkuidWi7QMU7ZoZOjGLD8Bxwrhzk6iL5nYNyEqSkPwVixQCNNKmJlx+ExwTy7FezPTdI3F6sLPxUt24= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=twnlZ+iA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="twnlZ+iA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FC48C4CEF1; Sun, 8 Jun 2025 20:40:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749415222; bh=vuKnESaBbThs2Ul53Pi+Hd5SXFdYZONrY95yvzz06xI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=twnlZ+iAOVl9p1TkuVd50Y4b6DefTMarMqIJ42O5ksBv7szNIMHdlLJeIRIdnwxS4 7ksyETRk0WETxu8e/m1A1pUbbzgtwLoyqL9jVFj53kFEwHWYPxTv4+10HDkHjBx0TO GosFIWEs5wh1rPMCuIQvPTqvmEDrGr4vAvXV8HUux9B4xe+lThjFhAQekAVy47vLdh HgeTOi3QcDZYBICQ4+IiHsr43taWBTLYcIy9krJsLXTPdelHDaXeZZkBaQuwG42Cz8 U41r89FloNQA5VrfBQuVvFusB6LaPNFCw8dhYIynMJl4huV0U8DOZIYipyAENdjhM/ FhjZeFA4/tyMQ== From: Hans de Goede To: Sebastian Reichel Cc: Hans de Goede , Mark Brown , AngeloGioacchino Del Regno , Linus Walleij , linux-pm@vger.kernel.org Subject: [PATCH 04/10] fixup! power: supply: core: battery-info: fully switch to fwnode Date: Sun, 8 Jun 2025 22:40:04 +0200 Message-ID: <20250608204010.37482-5-hansg@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250608204010.37482-1-hansg@kernel.org> References: <20250608204010.37482-1-hansg@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 After ("power: supply: core: battery-info: fully switch to fwnode") power_supply_get_battery_info() will always fail for battery fwnodes which do not define a "resistance-temp-table". Fix this by cleanly exiting on both 0 and EINVAL returns from fwnode_property_count_u32(fwnode, "resistance-temp-table") which indicates that the property is empty or not there. While at it also fix: 1. The weird -ENOMEM return for other errors. For other errors propagate the existing error or -EINVAL for an odd proplen. 2. Wrongly using "goto out_ret_pointer" on errors, out_ret_pointer should only be used on success, error paths should use out_put_node; Signed-off-by: Hans de Goede --- drivers/power/supply/power_supply_core.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index a8d1fe66e248..9bbc3be2e483 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -795,19 +795,20 @@ int power_supply_get_battery_info(struct power_supply *psy, } proplen = fwnode_property_count_u32(fwnode, "resistance-temp-table"); - if (proplen < 0 || proplen % 2 != 0) { + if (proplen == 0 || proplen == -EINVAL) { + err = 0; + goto out_ret_pointer; + } else if (proplen < 0 || proplen % 2 != 0) { power_supply_put_battery_info(psy, info); - err = -ENOMEM; - goto out_ret_pointer; - } else if (proplen == 0) { - goto out_ret_pointer; + err = (proplen < 0) ? proplen : -EINVAL; + goto out_put_node; } propdata = kcalloc(proplen, sizeof(*propdata), GFP_KERNEL); if (!propdata) { power_supply_put_battery_info(psy, info); err = -ENOMEM; - goto out_ret_pointer; + goto out_put_node; } err = fwnode_property_read_u32_array(fwnode, "resistance-temp-table", From patchwork Sun Jun 8 20:40:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 895084 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6BF318CC1C for ; Sun, 8 Jun 2025 20:40:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415224; cv=none; b=P3xTrWlAWhYmZGdXSszKR/USUe/zm6k9tmj7n54Sl808i0FgcoBNrcb2Cjxscl90QjfJO/FY6TplpinzsEUVq5otRwByTlDf+DkfsQ4F5NlBao2t7/KHCLoYN8c2nVkRe7dopGwjO8Smbl32/5mibJkhC8K/r6rD7qY9k/qNf4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415224; c=relaxed/simple; bh=XjWXf4ihzkPZQ/GBJNNvWYLpMFhhjXWcLArLlUN5BXE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iHieqp+0eYfNOp06p9MDFPtGcnpTRmT47fozYKPr3El43SBOVSKCkphfMzeHfkzomt2dILpLAJngVBVANDr0unbrviUROZ42+5nDIftZmoqVAqoxRq57bZPPjIYKyuH7dCaus1+mvUp4nx/ZIioX0PENdz7O63o2d54ihhIB71Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WwPT832j; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WwPT832j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA467C4CEEE; Sun, 8 Jun 2025 20:40:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749415224; bh=XjWXf4ihzkPZQ/GBJNNvWYLpMFhhjXWcLArLlUN5BXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WwPT832jsmabkb09kW2+L+TuHHIrAmhzn7yUm1chbREj0Oxb39Wutyn22HaOb0QVA 5N/8s6zGVf5nblQfOZNNxxNlwgMOUGpw579qdC0y0YM9q1vQQyXpmoEzmsQqBRc/z8 ebUW1pamKiNo6SG2ezNFhGgBW4YUNcqzWBt/wEI9beTaAt/tw3jeflZBtDvLOdXQ7N GKmxkBPuJ+i60jl167uKPe8CUd+yD1RaZONG4kFVdsZ80YqgmVkXcKfWmV/mjxeTBV cRRPxxyFM+C/668Gspm3yCFT0iU2FBE3BGErvTo0epli0HM+BTPQrjANcTwugrUyJJ wXxK6EoUAnb6g== From: Hans de Goede To: Sebastian Reichel Cc: Hans de Goede , Mark Brown , AngeloGioacchino Del Regno , Linus Walleij , linux-pm@vger.kernel.org Subject: [PATCH 05/10] fixup! power: supply: core: battery-info: fully switch to fwnode Date: Sun, 8 Jun 2025 22:40:05 +0200 Message-ID: <20250608204010.37482-6-hansg@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250608204010.37482-1-hansg@kernel.org> References: <20250608204010.37482-1-hansg@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 propname must NOT be manually free-ed here since it is marked __free(kfree), freeing it will cause a double-free bug. Also move propdata to be a __free(kfree) value for consistency and also for cleaner code. Signed-off-by: Hans de Goede --- drivers/power/supply/power_supply_core.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 9bbc3be2e483..f2c79f15838d 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -588,7 +588,7 @@ int power_supply_get_battery_info(struct power_supply *psy, struct fwnode_handle *srcnode, *fwnode; const char *value; int err, len, index, proplen; - u32 *propdata; + u32 *propdata __free(kfree) = NULL; u32 min_max[2]; srcnode = dev_fwnode(&psy->dev); @@ -758,9 +758,9 @@ int power_supply_get_battery_info(struct power_supply *psy, err = -EINVAL; goto out_put_node; } - propdata = kcalloc(proplen, sizeof(*propdata), GFP_KERNEL); + + u32 *propdata __free(kfree) = kcalloc(proplen, sizeof(*propdata), GFP_KERNEL); if (!propdata) { - kfree(propname); power_supply_put_battery_info(psy, info); err = -EINVAL; goto out_put_node; @@ -768,8 +768,6 @@ int power_supply_get_battery_info(struct power_supply *psy, err = fwnode_property_read_u32_array(fwnode, propname, propdata, proplen); if (err < 0) { dev_err(&psy->dev, "failed to get %s\n", propname); - kfree(propname); - kfree(propdata); power_supply_put_battery_info(psy, info); goto out_put_node; } @@ -780,7 +778,6 @@ int power_supply_get_battery_info(struct power_supply *psy, info->ocv_table[index] = table = devm_kcalloc(&psy->dev, tab_len, sizeof(*table), GFP_KERNEL); if (!info->ocv_table[index]) { - kfree(propdata); power_supply_put_battery_info(psy, info); err = -ENOMEM; goto out_put_node; @@ -790,8 +787,6 @@ int power_supply_get_battery_info(struct power_supply *psy, table[i].ocv = propdata[i*2]; table[i].capacity = propdata[i*2+1]; } - - kfree(propdata); } proplen = fwnode_property_count_u32(fwnode, "resistance-temp-table"); @@ -814,7 +809,6 @@ int power_supply_get_battery_info(struct power_supply *psy, err = fwnode_property_read_u32_array(fwnode, "resistance-temp-table", propdata, proplen); if (err < 0) { - kfree(propdata); power_supply_put_battery_info(psy, info); goto out_put_node; } @@ -825,7 +819,6 @@ int power_supply_get_battery_info(struct power_supply *psy, sizeof(*resist_table), GFP_KERNEL); if (!info->resist_table) { - kfree(propdata); power_supply_put_battery_info(psy, info); err = -ENOMEM; goto out_put_node; @@ -836,8 +829,6 @@ int power_supply_get_battery_info(struct power_supply *psy, resist_table[index].resistance = propdata[index*2+1]; } - kfree(propdata); - out_ret_pointer: /* Finally return the whole thing */ *info_out = info; From patchwork Sun Jun 8 20:40:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 894872 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E086F18CC1C for ; Sun, 8 Jun 2025 20:40:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415227; cv=none; b=LWxO+OdHSemcLSDN7zWif8j9K7R+f83tsLTEfjeZXwtG9G51vMchWqmULw0xdzsq3YSYDK6hfCwsYNNQGtFESgu+eg+CUpGMe02CgtaxmmCYEaKZF/boHNB9VuUMPV34QXGLtJ20gDr0F48aJfm5qhdgMQH6aYjPQi9o+ZENKts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415227; c=relaxed/simple; bh=hPu2LL4qVzNGjA9lUidgftSqpBH/n84hvsTHJ5/6g7E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n+f3YDdx73NODjxIg2RlKV0Aupwfv1OZHARf3Sjj1AKmDNKvlmXw2bIZziJ440CcMG/IWtU1wmbCq6wM0vxLtzAMMurWFWR0FHdv2TeWL4SfmESRMdWG9z72De8b0gQ3DwBcYz0cXUN+A4yOmQu7XbxKAmmAdctigPp6Ymgu5f8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ESA/kaG6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ESA/kaG6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D12C0C4CEF2; Sun, 8 Jun 2025 20:40:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749415226; bh=hPu2LL4qVzNGjA9lUidgftSqpBH/n84hvsTHJ5/6g7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ESA/kaG6ruIs4KA6EpGUqm1MhenI4zUfVp4XLMDdPZg7PN+QNZmWgtMzavpYEQUrx 1cC1FAs7voSiJkQw1RKl3GJccxAhvUX05q6J8zKLroZ+UfQ3V7gq57j0Gai9FZgI8Z y1dqRkFP6evJYptywEAM6vyEsyh1xobTxIkJoSRkXS85XjwZs3f/tZMOEVZidQM6Ix 3d8sh0aHdShRy0W139OmRmiTH2bbrCgVN8ApGPij9D/vhWZkYE4D9NfpvP4kHJkH0D l7RTRi4Tpxtpw2qm7pCPLMd3x2filUBUWRE0VgPATa5KWkl6qLEoUN2j2MkfbYrvzN 96CtXxw0SayLw== From: Hans de Goede To: Sebastian Reichel Cc: Hans de Goede , Mark Brown , AngeloGioacchino Del Regno , Linus Walleij , linux-pm@vger.kernel.org, Sebastian Reichel Subject: [PATCH 06/10] power: supply: core: convert to fwnnode Date: Sun, 8 Jun 2025 22:40:06 +0200 Message-ID: <20250608204010.37482-7-hansg@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250608204010.37482-1-hansg@kernel.org> References: <20250608204010.37482-1-hansg@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Sebastian Reichel Replace any DT specific code with fwnode in the power-supply core. Reviewed-by: AngeloGioacchino Del Regno Signed-off-by: Sebastian Reichel Link: https://lore.kernel.org/r/20250430-psy-core-convert-to-fwnode-v2-4-f9643b958677@collabora.com Reviewed-by: Hans de Goede Signed-off-by: Hans de Goede --- drivers/power/supply/bq2415x_charger.c | 2 +- drivers/power/supply/power_supply_core.c | 65 ++++++++++++------------ include/linux/power_supply.h | 2 +- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/drivers/power/supply/bq2415x_charger.c b/drivers/power/supply/bq2415x_charger.c index 9e3b9181ee76..1ecbca510bba 100644 --- a/drivers/power/supply/bq2415x_charger.c +++ b/drivers/power/supply/bq2415x_charger.c @@ -1674,7 +1674,7 @@ static int bq2415x_probe(struct i2c_client *client) /* Query for initial reported_mode and set it */ if (bq->nb.notifier_call) { if (np) { - notify_psy = power_supply_get_by_phandle(np, + notify_psy = power_supply_get_by_phandle(of_fwnode_handle(np), "ti,usb-charger-detection"); if (IS_ERR(notify_psy)) notify_psy = NULL; diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index f2c79f15838d..2d83bb125a48 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -196,24 +195,24 @@ static int __power_supply_populate_supplied_from(struct power_supply *epsy, void *data) { struct power_supply *psy = data; - struct device_node *np; + struct fwnode_handle *np; int i = 0; do { - np = of_parse_phandle(psy->dev.of_node, "power-supplies", i++); - if (!np) + np = fwnode_find_reference(psy->dev.fwnode, "power-supplies", i++); + if (IS_ERR(np)) break; - if (np == epsy->dev.of_node) { + if (np == epsy->dev.fwnode) { dev_dbg(&psy->dev, "%s: Found supply : %s\n", psy->desc->name, epsy->desc->name); psy->supplied_from[i-1] = (char *)epsy->desc->name; psy->num_supplies++; - of_node_put(np); + fwnode_handle_put(np); break; } - of_node_put(np); - } while (np); + fwnode_handle_put(np); + } while (!IS_ERR(np)); return 0; } @@ -232,16 +231,16 @@ static int power_supply_populate_supplied_from(struct power_supply *psy) static int __power_supply_find_supply_from_node(struct power_supply *epsy, void *data) { - struct device_node *np = data; + struct fwnode_handle *fwnode = data; /* returning non-zero breaks out of power_supply_for_each_psy loop */ - if (epsy->dev.of_node == np) + if (epsy->dev.fwnode == fwnode) return 1; return 0; } -static int power_supply_find_supply_from_node(struct device_node *supply_node) +static int power_supply_find_supply_from_fwnode(struct fwnode_handle *supply_node) { int error; @@ -249,7 +248,7 @@ static int power_supply_find_supply_from_node(struct device_node *supply_node) * power_supply_for_each_psy() either returns its own errors or values * returned by __power_supply_find_supply_from_node(). * - * __power_supply_find_supply_from_node() will return 0 (no match) + * __power_supply_find_supply_from_fwnode() will return 0 (no match) * or 1 (match). * * We return 0 if power_supply_for_each_psy() returned 1, -EPROBE_DEFER if @@ -262,7 +261,7 @@ static int power_supply_find_supply_from_node(struct device_node *supply_node) static int power_supply_check_supplies(struct power_supply *psy) { - struct device_node *np; + struct fwnode_handle *np; int cnt = 0; /* If there is already a list honor it */ @@ -270,24 +269,24 @@ static int power_supply_check_supplies(struct power_supply *psy) return 0; /* No device node found, nothing to do */ - if (!psy->dev.of_node) + if (!psy->dev.fwnode) return 0; do { int ret; - np = of_parse_phandle(psy->dev.of_node, "power-supplies", cnt++); - if (!np) + np = fwnode_find_reference(psy->dev.fwnode, "power-supplies", cnt++); + if (IS_ERR(np)) break; - ret = power_supply_find_supply_from_node(np); - of_node_put(np); + ret = power_supply_find_supply_from_fwnode(np); + fwnode_handle_put(np); if (ret) { dev_dbg(&psy->dev, "Failed to find supply!\n"); return ret; } - } while (np); + } while (!IS_ERR(np)); /* Missing valid "power-supplies" entries */ if (cnt == 1) @@ -498,14 +497,14 @@ void power_supply_put(struct power_supply *psy) EXPORT_SYMBOL_GPL(power_supply_put); #ifdef CONFIG_OF -static int power_supply_match_device_node(struct device *dev, const void *data) +static int power_supply_match_device_fwnode(struct device *dev, const void *data) { - return dev->parent && dev->parent->of_node == data; + return dev->parent && dev_fwnode(dev->parent) == data; } /** * power_supply_get_by_phandle() - Search for a power supply and returns its ref - * @np: Pointer to device node holding phandle property + * @fwnode: Pointer to fwnode holding phandle property * @property: Name of property holding a power supply name * * If power supply was found, it increases reference count for the @@ -515,21 +514,21 @@ static int power_supply_match_device_node(struct device *dev, const void *data) * Return: On success returns a reference to a power supply with * matching name equals to value under @property, NULL or ERR_PTR otherwise. */ -struct power_supply *power_supply_get_by_phandle(struct device_node *np, - const char *property) +struct power_supply *power_supply_get_by_phandle(struct fwnode_handle *fwnode, + const char *property) { - struct device_node *power_supply_np; + struct fwnode_handle *power_supply_fwnode; struct power_supply *psy = NULL; struct device *dev; - power_supply_np = of_parse_phandle(np, property, 0); - if (!power_supply_np) - return ERR_PTR(-ENODEV); + power_supply_fwnode = fwnode_find_reference(fwnode, property, 0); + if (IS_ERR(power_supply_fwnode)) + return ERR_CAST(power_supply_fwnode); - dev = class_find_device(&power_supply_class, NULL, power_supply_np, - power_supply_match_device_node); + dev = class_find_device(&power_supply_class, NULL, power_supply_fwnode, + power_supply_match_device_fwnode); - of_node_put(power_supply_np); + fwnode_handle_put(power_supply_fwnode); if (dev) { psy = dev_to_psy(dev); @@ -561,14 +560,14 @@ struct power_supply *devm_power_supply_get_by_phandle(struct device *dev, { struct power_supply **ptr, *psy; - if (!dev->of_node) + if (!dev_fwnode(dev)) return ERR_PTR(-ENODEV); ptr = devres_alloc(devm_power_supply_put, sizeof(*ptr), GFP_KERNEL); if (!ptr) return ERR_PTR(-ENOMEM); - psy = power_supply_get_by_phandle(dev->of_node, property); + psy = power_supply_get_by_phandle(dev_fwnode(dev), property); if (IS_ERR_OR_NULL(psy)) { devres_free(ptr); } else { diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 3e52883f866b..c22ecb46098f 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -807,7 +807,7 @@ static inline struct power_supply *power_supply_get_by_name(const char *name) { return NULL; } #endif #ifdef CONFIG_OF -extern struct power_supply *power_supply_get_by_phandle(struct device_node *np, +extern struct power_supply *power_supply_get_by_phandle(struct fwnode_handle *fwnode, const char *property); extern struct power_supply *devm_power_supply_get_by_phandle( struct device *dev, const char *property); From patchwork Sun Jun 8 20:40:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 895083 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4961224FA for ; Sun, 8 Jun 2025 20:40:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415228; cv=none; b=IXhGW2vljydg6p82rbtS5OSxGtczNHDz5CHNcXFoAVV0kL3A1IsSJzcnJBQ/9HSXfVAdGdL0FpDkjzTAIN6pJp1t3YVmpdEwPP0hMnPsohBCh6utbgedGfMfnjqnnNBzSu6NLuCBmuXnhfPKeEPma2JB08nBWuRr5t1UY/qEpqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415228; c=relaxed/simple; bh=x1mMn/wY5QTaCLUxdwr5SYEvhcXaA8+bA4Kkj9HXJ1I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sI16GIUaVizp4ZAI7k1XN3rq1tkCdfIDkNJB4UkCeEwwL1TOa+SgGmaIRmAIkhh6E6jqCvcCg+ufwcyvPD48X2RcRh43n1ANyIVGRZzhhdEMyzE4xPTBRgua9nxYIGDwbJZGh8jmgQ2XPxawLsw7mwGhPo6td43IqGlZ2jkxekA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KPrg2+P+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KPrg2+P+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E383CC4CEEE; Sun, 8 Jun 2025 20:40:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749415228; bh=x1mMn/wY5QTaCLUxdwr5SYEvhcXaA8+bA4Kkj9HXJ1I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KPrg2+P++/pUoyYWq8goX6A2TrNfXcUqZEYiz+rRD9EgZHa8NYsnaalOhL6vhExLm FhmLtfzHbTxl8VmZTuV11RqWKhEJsdoOzCtgFGjQ9zulBp0iDRItc/kvuCDwmYtFN8 w2ivp3sd9lYipV4I7/S+nvkUZrA1Bpob451L+Kiew4WrQs40hq47xeiQl83Xql9mdn zSDUrmITPgI1g0C/Ai/fdQqADrdXNxpCU4lY77xBtep/ebu3LJdQdVOTk9p7tVMPyD Fx75+xltaZqos5eWgQBA7xXzz0Quox8V1dLyE/lGcM09vasPR9S7cT1pGlbEu3pTa2 J/l1pvpLbYfFA== From: Hans de Goede To: Sebastian Reichel Cc: Hans de Goede , Mark Brown , AngeloGioacchino Del Regno , Linus Walleij , linux-pm@vger.kernel.org, Sebastian Reichel Subject: [PATCH 07/10] power: supply: core: rename power_supply_get_by_phandle to power_supply_get_by_reference Date: Sun, 8 Jun 2025 22:40:07 +0200 Message-ID: <20250608204010.37482-8-hansg@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250608204010.37482-1-hansg@kernel.org> References: <20250608204010.37482-1-hansg@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Sebastian Reichel (devm_)power_supply_get_by_phandle now internally uses fwnode and are no longer DT specific. Thus drop the ifdef check for CONFIG_OF and rename to (devm_)power_supply_get_by_reference to avoid the DT terminology. Signed-off-by: Sebastian Reichel Link: https://lore.kernel.org/r/20250430-psy-core-convert-to-fwnode-v2-5-f9643b958677@collabora.com Reviewed-by: Hans de Goede Signed-off-by: Hans de Goede --- drivers/phy/allwinner/phy-sun4i-usb.c | 2 +- drivers/power/supply/bq2415x_charger.c | 2 +- drivers/power/supply/power_supply_core.c | 22 ++++++++++------------ include/linux/power_supply.h | 15 +++------------ 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c index 29b8fd4b9351..8873aed3a52a 100644 --- a/drivers/phy/allwinner/phy-sun4i-usb.c +++ b/drivers/phy/allwinner/phy-sun4i-usb.c @@ -754,7 +754,7 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev) } if (of_property_present(np, "usb0_vbus_power-supply")) { - data->vbus_power_supply = devm_power_supply_get_by_phandle(dev, + data->vbus_power_supply = devm_power_supply_get_by_reference(dev, "usb0_vbus_power-supply"); if (IS_ERR(data->vbus_power_supply)) { dev_err(dev, "Couldn't get the VBUS power supply\n"); diff --git a/drivers/power/supply/bq2415x_charger.c b/drivers/power/supply/bq2415x_charger.c index 1ecbca510bba..917c26ee56bc 100644 --- a/drivers/power/supply/bq2415x_charger.c +++ b/drivers/power/supply/bq2415x_charger.c @@ -1674,7 +1674,7 @@ static int bq2415x_probe(struct i2c_client *client) /* Query for initial reported_mode and set it */ if (bq->nb.notifier_call) { if (np) { - notify_psy = power_supply_get_by_phandle(of_fwnode_handle(np), + notify_psy = power_supply_get_by_reference(of_fwnode_handle(np), "ti,usb-charger-detection"); if (IS_ERR(notify_psy)) notify_psy = NULL; diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 2d83bb125a48..aedb20c1d276 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -496,14 +496,13 @@ void power_supply_put(struct power_supply *psy) } EXPORT_SYMBOL_GPL(power_supply_put); -#ifdef CONFIG_OF static int power_supply_match_device_fwnode(struct device *dev, const void *data) { return dev->parent && dev_fwnode(dev->parent) == data; } /** - * power_supply_get_by_phandle() - Search for a power supply and returns its ref + * power_supply_get_by_reference() - Search for a power supply and returns its ref * @fwnode: Pointer to fwnode holding phandle property * @property: Name of property holding a power supply name * @@ -514,8 +513,8 @@ static int power_supply_match_device_fwnode(struct device *dev, const void *data * Return: On success returns a reference to a power supply with * matching name equals to value under @property, NULL or ERR_PTR otherwise. */ -struct power_supply *power_supply_get_by_phandle(struct fwnode_handle *fwnode, - const char *property) +struct power_supply *power_supply_get_by_reference(struct fwnode_handle *fwnode, + const char *property) { struct fwnode_handle *power_supply_fwnode; struct power_supply *psy = NULL; @@ -537,7 +536,7 @@ struct power_supply *power_supply_get_by_phandle(struct fwnode_handle *fwnode, return psy; } -EXPORT_SYMBOL_GPL(power_supply_get_by_phandle); +EXPORT_SYMBOL_GPL(power_supply_get_by_reference); static void devm_power_supply_put(struct device *dev, void *res) { @@ -547,16 +546,16 @@ static void devm_power_supply_put(struct device *dev, void *res) } /** - * devm_power_supply_get_by_phandle() - Resource managed version of - * power_supply_get_by_phandle() + * devm_power_supply_get_by_reference() - Resource managed version of + * power_supply_get_by_reference() * @dev: Pointer to device holding phandle property * @property: Name of property holding a power supply phandle * * Return: On success returns a reference to a power supply with * matching name equals to value under @property, NULL or ERR_PTR otherwise. */ -struct power_supply *devm_power_supply_get_by_phandle(struct device *dev, - const char *property) +struct power_supply *devm_power_supply_get_by_reference(struct device *dev, + const char *property) { struct power_supply **ptr, *psy; @@ -567,7 +566,7 @@ struct power_supply *devm_power_supply_get_by_phandle(struct device *dev, if (!ptr) return ERR_PTR(-ENOMEM); - psy = power_supply_get_by_phandle(dev_fwnode(dev), property); + psy = power_supply_get_by_reference(dev_fwnode(dev), property); if (IS_ERR_OR_NULL(psy)) { devres_free(ptr); } else { @@ -576,8 +575,7 @@ struct power_supply *devm_power_supply_get_by_phandle(struct device *dev, } return psy; } -EXPORT_SYMBOL_GPL(devm_power_supply_get_by_phandle); -#endif /* CONFIG_OF */ +EXPORT_SYMBOL_GPL(devm_power_supply_get_by_reference); int power_supply_get_battery_info(struct power_supply *psy, struct power_supply_battery_info **info_out) diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index c22ecb46098f..73bf20031449 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -806,19 +806,10 @@ static inline void power_supply_put(struct power_supply *psy) {} static inline struct power_supply *power_supply_get_by_name(const char *name) { return NULL; } #endif -#ifdef CONFIG_OF -extern struct power_supply *power_supply_get_by_phandle(struct fwnode_handle *fwnode, - const char *property); -extern struct power_supply *devm_power_supply_get_by_phandle( +extern struct power_supply *power_supply_get_by_reference(struct fwnode_handle *fwnode, + const char *property); +extern struct power_supply *devm_power_supply_get_by_reference( struct device *dev, const char *property); -#else /* !CONFIG_OF */ -static inline struct power_supply * -power_supply_get_by_phandle(struct device_node *np, const char *property) -{ return NULL; } -static inline struct power_supply * -devm_power_supply_get_by_phandle(struct device *dev, const char *property) -{ return NULL; } -#endif /* CONFIG_OF */ extern const enum power_supply_property power_supply_battery_info_properties[]; extern const size_t power_supply_battery_info_properties_size; From patchwork Sun Jun 8 20:40:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 894871 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BF70224FA for ; Sun, 8 Jun 2025 20:40:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415230; cv=none; b=fK6gIvnYVPpQ4QqD/y3YMe7aPCtjXVYPT69CCmJ1TeoUs9Cg8RoJUofFhyOFQLDlACQ5kqA9of1kwTNwBVCF6DT5e7tmijV5ckCrZeEdhVf67DNZRn8O3Y3ZU5hLCZk8ZqrXtVvAas12Eyi97De34Mtoys7Gjw2Ys8nvTLj5OO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415230; c=relaxed/simple; bh=p5EHmB8KXCz3QZJRZ4egAH/kUseuWnlTXgNyawhegJU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dBV7nZ2qi239FgQISj1Fg3wuY/uRamsgw4fRpH9h/e2FY0uGKGnIczUJVswrkQmEN1DXFVXhNrycns2iDbtkYXKq89BKRp5CvoLIct4pP5sIDCNZ04IKklAaVvPe5HUIM/2Nzd1ND6u4qBvddZU4Z5Bp1wERBNqbSEV8SMH78As= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TOD4+Jt8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TOD4+Jt8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 015B9C4CEEE; Sun, 8 Jun 2025 20:40:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749415230; bh=p5EHmB8KXCz3QZJRZ4egAH/kUseuWnlTXgNyawhegJU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TOD4+Jt85GCj9jAkWw5xIp5E8SQnk/AJW8zMt16ajggjpkqQoDiAKoQCwhThrArPp OOFCG7N7sVUxLMr3GJWXn/SQrXwDptQ94rnEfOHUYzluim/XyDuvgKhbAPEntnm0sa tdAQqeausDFRVKE2HZSsULPC7qlHsd3mL7lhHG9xywUSBkUe4cvrKgEXMk3Z2O6hAx WPuw0mpsCOG6OaME/1+03VM0B/VmbkX43wT3OsYvC5+sQI7d5Z3C8dtD9hKJMs2X4O 7fGiXc+bB/snuGgxgNkHC8HXt3qWThRPkmViylFx6x7SzoBdgcfYk9gCRZ1uIzkZGu Miq2g9dWeY0RA== From: Hans de Goede To: Sebastian Reichel Cc: Hans de Goede , Mark Brown , AngeloGioacchino Del Regno , Linus Walleij , linux-pm@vger.kernel.org Subject: [PATCH 08/10] power: supply: ug3105_battery: Use psy->battery_info Date: Sun, 8 Jun 2025 22:40:08 +0200 Message-ID: <20250608204010.37482-9-hansg@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250608204010.37482-1-hansg@kernel.org> References: <20250608204010.37482-1-hansg@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For POWER_SUPPLY_TYPE_BATTERY power-supplies the core already calls power_supply_get_battery_info() and stores the result in psy->battery_info. Use psy->battery_info instead of having the driver call power_supply_get_battery_info() itself. Signed-off-by: Hans de Goede --- drivers/power/supply/ug3105_battery.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/power/supply/ug3105_battery.c b/drivers/power/supply/ug3105_battery.c index 38e23bdd4603..806f6892e189 100644 --- a/drivers/power/supply/ug3105_battery.c +++ b/drivers/power/supply/ug3105_battery.c @@ -69,7 +69,6 @@ struct ug3105_chip { struct i2c_client *client; struct power_supply *psy; - struct power_supply_battery_info *info; struct delayed_work work; struct mutex lock; int ocv[UG3105_MOV_AVG_WINDOW]; /* micro-volt */ @@ -103,7 +102,8 @@ static int ug3105_read_word(struct i2c_client *client, u8 reg) static int ug3105_get_status(struct ug3105_chip *chip) { - int full = chip->info->constant_charge_voltage_max_uv - UG3105_FULL_BAT_HYST_UV; + int full = chip->psy->battery_info->constant_charge_voltage_max_uv - + UG3105_FULL_BAT_HYST_UV; if (chip->curr > UG3105_CURR_HYST_UA) return POWER_SUPPLY_STATUS_CHARGING; @@ -164,7 +164,7 @@ static int ug3105_get_capacity(struct ug3105_chip *chip) ocv_diff = ocv_capacity_tbl[i] - chip->ocv_avg; ocv_step = ocv_capacity_tbl[i] - ocv_capacity_tbl[i - 1]; /* scale 0-110% down to 0-100% for LiPo HV */ - if (chip->info->constant_charge_voltage_max_uv >= 4300000) + if (chip->psy->battery_info->constant_charge_voltage_max_uv >= 4300000) return (i * 500 - ocv_diff * 500 / ocv_step) / 110; else return i * 5 - ocv_diff * 5 / ocv_step; @@ -401,12 +401,9 @@ static int ug3105_probe(struct i2c_client *client) if (IS_ERR(psy)) return PTR_ERR(psy); - ret = power_supply_get_battery_info(psy, &chip->info); - if (ret) - return ret; - - if (chip->info->factory_internal_resistance_uohm == -EINVAL || - chip->info->constant_charge_voltage_max_uv == -EINVAL) { + if (!psy->battery_info || + psy->battery_info->factory_internal_resistance_uohm == -EINVAL || + psy->battery_info->constant_charge_voltage_max_uv == -EINVAL) { dev_err(dev, "error required properties are missing\n"); return -ENODEV; } @@ -422,7 +419,7 @@ static int ug3105_probe(struct i2c_client *client) chip->ua_per_unit = 8100000 / curr_sense_res_uohm; /* Use provided internal resistance as start point (in milli-ohm) */ - chip->intern_res_avg = chip->info->factory_internal_resistance_uohm / 1000; + chip->intern_res_avg = psy->battery_info->factory_internal_resistance_uohm / 1000; /* Also add it to the internal resistance moving average window */ chip->intern_res[0] = chip->intern_res_avg; chip->intern_res_avg_index = 1; From patchwork Sun Jun 8 20:40:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 895082 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76D6B224FA for ; Sun, 8 Jun 2025 20:40:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415232; cv=none; b=pPd2hWYh0UEk6i+QZ4vpCYLHt3wpQgowJ7xtD5NuHnpIznCoo4jZuRgsOR3HwMwE2+Z8WLEkj5pbq18B3pYSZ1MGOJ7V0BoLDVxtJvzSkYpsyB6KwmFaHOeBQ+qt1uDpUqLGR4DVocOXXOkpYqt0C8nK0+bzZMlnwoNgeyocLGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415232; c=relaxed/simple; bh=fbl7SlM7GIRGQUhir4c7sfNxmoDHDR/ccZ6G/rhifCU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TpKBfqBDzGj30nEWEKmKuVNVUmHAQ4C5eV7qPjK4+qqsVtzh1/dmvrOqMV3cjH3XlcFtVqhJQPUuinglfioprE2/1Hs/hQ7tGkxqbKn0EfJCMeI1PlonuZ4CyFC8l/2+seJKx+erlpWcqlhDOv2ct175wPxxTIFoK0ntJQ4bOFo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gIPH8USX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gIPH8USX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DAEFBC4CEEE; Sun, 8 Jun 2025 20:40:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749415232; bh=fbl7SlM7GIRGQUhir4c7sfNxmoDHDR/ccZ6G/rhifCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gIPH8USX9T55gnud2trwuCqEn8/MiAUtBgXmMMvgvyg2o3tTlICQ5AhwzG5rh+UXp c+CidRMya0k79kVfmvb/tZYoK3gAyQ5TxcPcp9m6pF+LIi4b8bUr3m7ccp6FvEJUSy CbtMQPvmxaP8cLcGNIYvo1gsFOAQ6k8+GQyAxLCULaYSpOK7k+hqbF8bXX9xGKAJ4F 8PfBg9Hdf84KIPJHTGOded+cEOESc/M9n9SB7YstjJ3TkKxXKQH7uvL71weusofRVf 0PX/g1H7ye0PPWE6lxxodLibA+tS4Zt2HUqFkCHhzG3+33l2EX/5ehkwx29PH94BuA qQEy9dczmTaAw== From: Hans de Goede To: Sebastian Reichel Cc: Hans de Goede , Mark Brown , AngeloGioacchino Del Regno , Linus Walleij , linux-pm@vger.kernel.org Subject: [PATCH 09/10] power: supply: ug3105_battery: Switch to power_supply_batinfo_ocv2cap() Date: Sun, 8 Jun 2025 22:40:09 +0200 Message-ID: <20250608204010.37482-10-hansg@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250608204010.37482-1-hansg@kernel.org> References: <20250608204010.37482-1-hansg@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replace the hardcoded ocv -> capacity table and the ug3105_get_capacity() helper with using the generic power_supply_batinfo_ocv2cap() function. Note this relies on the battery fwnode providing at least 1 "ocv-capacity-table", if that is missing probe() will now fail with EINVAL. Signed-off-by: Hans de Goede --- drivers/power/supply/ug3105_battery.c | 68 ++++----------------------- 1 file changed, 10 insertions(+), 58 deletions(-) diff --git a/drivers/power/supply/ug3105_battery.c b/drivers/power/supply/ug3105_battery.c index 806f6892e189..e8a1de7cade0 100644 --- a/drivers/power/supply/ug3105_battery.c +++ b/drivers/power/supply/ug3105_battery.c @@ -66,6 +66,8 @@ #define UG3105_LOW_BAT_UV 3700000 #define UG3105_FULL_BAT_HYST_UV 38000 +#define AMBIENT_TEMP_CELCIUS 25 + struct ug3105_chip { struct i2c_client *client; struct power_supply *psy; @@ -117,62 +119,6 @@ static int ug3105_get_status(struct ug3105_chip *chip) return POWER_SUPPLY_STATUS_NOT_CHARGING; } -static int ug3105_get_capacity(struct ug3105_chip *chip) -{ - /* - * OCV voltages in uV for 0-110% in 5% increments, the 100-110% is - * for LiPo HV (High-Voltage) bateries which can go up to 4.35V - * instead of the usual 4.2V. - */ - static const int ocv_capacity_tbl[23] = { - 3350000, - 3610000, - 3690000, - 3710000, - 3730000, - 3750000, - 3770000, - 3786667, - 3803333, - 3820000, - 3836667, - 3853333, - 3870000, - 3907500, - 3945000, - 3982500, - 4020000, - 4075000, - 4110000, - 4150000, - 4200000, - 4250000, - 4300000, - }; - int i, ocv_diff, ocv_step; - - if (chip->ocv_avg < ocv_capacity_tbl[0]) - return 0; - - if (chip->status == POWER_SUPPLY_STATUS_FULL) - return 100; - - for (i = 1; i < ARRAY_SIZE(ocv_capacity_tbl); i++) { - if (chip->ocv_avg > ocv_capacity_tbl[i]) - continue; - - ocv_diff = ocv_capacity_tbl[i] - chip->ocv_avg; - ocv_step = ocv_capacity_tbl[i] - ocv_capacity_tbl[i - 1]; - /* scale 0-110% down to 0-100% for LiPo HV */ - if (chip->psy->battery_info->constant_charge_voltage_max_uv >= 4300000) - return (i * 500 - ocv_diff * 500 / ocv_step) / 110; - else - return i * 5 - ocv_diff * 5 / ocv_step; - } - - return 100; -} - static void ug3105_work(struct work_struct *work) { struct ug3105_chip *chip = container_of(work, struct ug3105_chip, @@ -231,7 +177,12 @@ static void ug3105_work(struct work_struct *work) chip->supplied = power_supply_am_i_supplied(psy); chip->status = ug3105_get_status(chip); - chip->capacity = ug3105_get_capacity(chip); + if (chip->status == POWER_SUPPLY_STATUS_FULL) + chip->capacity = 100; + else + chip->capacity = power_supply_batinfo_ocv2cap(chip->psy->battery_info, + chip->ocv_avg, + AMBIENT_TEMP_CELCIUS); /* * Skip internal resistance calc on charger [un]plug and @@ -403,7 +354,8 @@ static int ug3105_probe(struct i2c_client *client) if (!psy->battery_info || psy->battery_info->factory_internal_resistance_uohm == -EINVAL || - psy->battery_info->constant_charge_voltage_max_uv == -EINVAL) { + psy->battery_info->constant_charge_voltage_max_uv == -EINVAL || + !psy->battery_info->ocv_table[0]) { dev_err(dev, "error required properties are missing\n"); return -ENODEV; } From patchwork Sun Jun 8 20:40:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 894870 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 569CA224FA for ; Sun, 8 Jun 2025 20:40:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415234; cv=none; b=kYZ12Vn5j/hBYJsN0N/2EpDC9NIQnySlljfeVQtf9GUswOOcLsA3VpKyaaP6uUkxNvKnsJ7x+qBjdgFNjsCwscc2gAVxYL3/5GtTUa2ZwsEP18lDtHpVDRvHtgn5Ojc5iKxXGQ67jbMwjDEb0X5LyLgIxq1szdQDKyc17basClg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749415234; c=relaxed/simple; bh=tC4bN7/oX2CSIZDOv0m5Rw+30FigfgLCD5+SuQCMSBU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fo6iTERzLRdWgNlzfCiboMGNTqm5r1hBVGe7XIq+/kJrJ7J1xdKpvYbJ6ZbO+Cofy5CwOuaCUKuv3AYiwdXWAccVIBCauHES40flSfqtJyUo2fWvHRFIbwHcOGFRClXWDErdenFXpp3IR1da0oFbGsF8YUrifUp5Z5huT2P2wqY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dzaMzJsW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dzaMzJsW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF818C4CEF1; Sun, 8 Jun 2025 20:40:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749415234; bh=tC4bN7/oX2CSIZDOv0m5Rw+30FigfgLCD5+SuQCMSBU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dzaMzJsWWI/NIKeIK4RzB1hUVOWUNxf6v7WeyZAbGoCDbiysPCNGpkAWrr4mCSTP4 A0MipYmRY6e8nwvIq71qqOwYFX8OhWSe2ZB6iPBs312ONx8YQN866DIbebvf2+chBT nngYk/6j3fw2SeN2ffm4zD5bZB+A4L2kiIqYK7WqYlzy41vVhuuw8kbfsS4AYMXJeg GfkoksrXS9sa8DC+gNOy1osX0i9J+xHHIm2TweZZsFMdy0syZrWLRMqT/C69Wo/Ffn ilSQdv8m8MkThz5qDFzeCZ8oQH631Pf4jce0qUXmByzprsYZyfGhgh2Ul4mT8NQ5gx rM80Scya9kyNg== From: Hans de Goede To: Sebastian Reichel Cc: Hans de Goede , Mark Brown , AngeloGioacchino Del Regno , Linus Walleij , linux-pm@vger.kernel.org Subject: [PATCH 10/10] power: supply: bq24190: Free battery_info Date: Sun, 8 Jun 2025 22:40:10 +0200 Message-ID: <20250608204010.37482-11-hansg@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250608204010.37482-1-hansg@kernel.org> References: <20250608204010.37482-1-hansg@kernel.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Call power_supply_put_battery_info() when bq24190_get_config() is done with it. The "struct power_supply_battery_info *info" pointer runs out of scope at the end of bq24190_get_config() so there is no need to keep it around after this. Note technically this is not a memleak fix, since all battery_info data is devm_alloc()-ed so it would still be free-ed when the driver is unbound. This just frees it as soon as the driver is done with it. Signed-off-by: Hans de Goede --- drivers/power/supply/bq24190_charger.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c index f0d97ab45bd8..cc6dad8f8e58 100644 --- a/drivers/power/supply/bq24190_charger.c +++ b/drivers/power/supply/bq24190_charger.c @@ -1982,6 +1982,8 @@ static int bq24190_get_config(struct bq24190_dev_info *bdi) v = info->constant_charge_voltage_max_uv; if (v >= bq24190_cvc_vreg_values[0] && v <= bdi->vreg_max) bdi->vreg = bdi->vreg_max = v; + + power_supply_put_battery_info(bdi->charger, info); } return 0;