From patchwork Tue Mar 14 22:55:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13175102 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 5B259C77B60 for ; Tue, 14 Mar 2023 22:55:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230200AbjCNWzp (ORCPT ); Tue, 14 Mar 2023 18:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231332AbjCNWzo (ORCPT ); Tue, 14 Mar 2023 18:55:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 953E439CC0; Tue, 14 Mar 2023 15:55:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 382E7B81BFF; Tue, 14 Mar 2023 22:55:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9900AC433D2; Tue, 14 Mar 2023 22:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678834539; bh=w+RHxqT9n38mgW/95l4s9XF2bsYwf020rGPTQmbmzcw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o09AGfXyvdqszwdCTVsMaIIPcjR9MQc0MNhPDsiMn2q2HEq4ZiqswaRkf+XdMqEgK 1tW5EQVBifPZC82jujAzTqlTNB8ITmNSal2dBccbT5oSjkZPPHfzhNTvBhMxEhHUhz Ta/tfimJWP3XoMo4rdt7RYPBt0cmpFA/5W4B0r99oOjAEQinZ83LbWE6trm1s2alYc HDSHMWaDcXUNw3PcoYoDZkZ+C1gQ1xiMY+4DiPzyMV5WrUhjj6gO9lJGSPNiXL81wz TuWiRnFJQgfiniUeupWwNV92u1SRlGQvsVHWxBHLlhZEvzidc5OVmpMyfK9ILdlZtK y9gyIUxza0YbA== Received: by mercury (Postfix, from userid 1000) id D35AA10605A2; Tue, 14 Mar 2023 23:55:36 +0100 (CET) From: Sebastian Reichel To: Sebastian Reichel Cc: Linus Walleij , Matti Vaittinen , Rob Herring , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCHv2 01/12] dt-bindings: power: supply: adc-battery: add binding Date: Tue, 14 Mar 2023 23:55:24 +0100 Message-Id: <20230314225535.1321736-2-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314225535.1321736-1-sre@kernel.org> References: <20230314225535.1321736-1-sre@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add binding for a battery that is only monitored via ADC channels and simple status GPIOs. Signed-off-by: Sebastian Reichel Reviewed-by: Matti Vaittinen Reviewed-by: Krzysztof Kozlowski Reviewed-by: Linus Walleij --- .../bindings/power/supply/adc-battery.yaml | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/adc-battery.yaml diff --git a/Documentation/devicetree/bindings/power/supply/adc-battery.yaml b/Documentation/devicetree/bindings/power/supply/adc-battery.yaml new file mode 100644 index 000000000000..ed9702caedff --- /dev/null +++ b/Documentation/devicetree/bindings/power/supply/adc-battery.yaml @@ -0,0 +1,70 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/supply/adc-battery.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: ADC battery + +maintainers: + - Sebastian Reichel + +description: + Basic battery capacity meter, which only reports basic battery data + via ADC channels and optionally indicate that the battery is full by + polling a GPIO line. + + The voltage is expected to be measured between the battery terminals + and mandatory. The optional current/power channel is expected to + monitor the current/power flowing out of the battery. Last but not + least the temperature channel is supposed to measure the battery + temperature. + +allOf: + - $ref: power-supply.yaml# + +properties: + compatible: + const: adc-battery + + charged-gpios: + description: + GPIO which signals that the battery is fully charged. The GPIO is + often provided by charger ICs, that are not software controllable. + maxItems: 1 + + io-channels: + minItems: 1 + maxItems: 4 + + io-channel-names: + minItems: 1 + items: + - const: voltage + - enum: [ current, power, temperature ] + - enum: [ power, temperature ] + - const: temperature + + monitored-battery: true + +required: + - compatible + - io-channels + - io-channel-names + - monitored-battery + +unevaluatedProperties: false + +examples: + - | + #include + + fuel-gauge { + compatible = "adc-battery"; + charged-gpios = <&gpio 42 GPIO_ACTIVE_HIGH>; + io-channels = <&adc 13>, <&adc 37>; + io-channel-names = "voltage", "current"; + + power-supplies = <&charger>; + monitored-battery = <&battery>; + }; From patchwork Tue Mar 14 22:55:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13175101 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 3F7B9C7618D for ; Tue, 14 Mar 2023 22:55:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231297AbjCNWzo (ORCPT ); Tue, 14 Mar 2023 18:55:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbjCNWzm (ORCPT ); Tue, 14 Mar 2023 18:55:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 411952006A; Tue, 14 Mar 2023 15:55:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 83DBE61A3D; Tue, 14 Mar 2023 22:55:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A22C1C4339C; Tue, 14 Mar 2023 22:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678834539; bh=LfCxBHujzwKHUQBqt8IRTefI9EZfCuzW0vphaX82Qts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RyMNCf2pdU3BmimnV2wTX9ppX/0+oTGW0nJWNV+5WuW5P+f0pWl3gsDronATuBR1x zRmlVAL++XI6Y9FSmFWtUamtKb1Q1VvE9hyytZQf6yIsVlmg/JvXsFbnFtGo5nU03S wTHBr0IPqdljswPREMzu8LQ3odmC/aq849X2zjYFghfJMGppcsjyewtPbzKzAxWPxj RYqWnNMXElxBinPG3HCaFd7RYo4w4daZPzLdQltZW0Kxdp+goQ5FIYkMZtyy+REAa7 U1bHtlUM1JKamHMp6bzN8RJ9cX8GpeU3I4FUhWYzGD6NNz1VTeuqhP33jq+awia05E bxC+sNIUeIPyA== Received: by mercury (Postfix, from userid 1000) id D3ED2106209E; Tue, 14 Mar 2023 23:55:36 +0100 (CET) From: Sebastian Reichel To: Sebastian Reichel Cc: Linus Walleij , Matti Vaittinen , Rob Herring , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCHv2 02/12] power: supply: core: auto-exposure of simple-battery data Date: Tue, 14 Mar 2023 23:55:25 +0100 Message-Id: <20230314225535.1321736-3-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314225535.1321736-1-sre@kernel.org> References: <20230314225535.1321736-1-sre@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add support for automatically exposing data from the simple-battery firmware node with a single configuration option in the power-supply device. Signed-off-by: Sebastian Reichel Reviewed-by: Matti Vaittinen --- drivers/power/supply/power_supply_core.c | 173 +++++++++++++++++++--- drivers/power/supply/power_supply_sysfs.c | 15 ++ include/linux/power_supply.h | 8 + 3 files changed, 178 insertions(+), 18 deletions(-) diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index f3d7c1da299f..842c27de4fac 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -388,7 +388,7 @@ static int __power_supply_get_supplier_property(struct device *dev, void *_data) struct psy_get_supplier_prop_data *data = _data; if (__power_supply_is_supplied_by(epsy, data->psy)) - if (!epsy->desc->get_property(epsy, data->psp, data->val)) + if (!power_supply_get_property(epsy, data->psp, data->val)) return 1; /* Success */ return 0; /* Continue iterating */ @@ -832,6 +832,133 @@ void power_supply_put_battery_info(struct power_supply *psy, } EXPORT_SYMBOL_GPL(power_supply_put_battery_info); +const enum power_supply_property power_supply_battery_info_properties[] = { + POWER_SUPPLY_PROP_TECHNOLOGY, + POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, + POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, + POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, + POWER_SUPPLY_PROP_PRECHARGE_CURRENT, + POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, + POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN, + POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX, + POWER_SUPPLY_PROP_TEMP_ALERT_MIN, + POWER_SUPPLY_PROP_TEMP_ALERT_MAX, + POWER_SUPPLY_PROP_TEMP_MIN, + POWER_SUPPLY_PROP_TEMP_MAX, +}; +EXPORT_SYMBOL_GPL(power_supply_battery_info_properties); + +const size_t power_supply_battery_info_properties_size = ARRAY_SIZE(power_supply_battery_info_properties); +EXPORT_SYMBOL_GPL(power_supply_battery_info_properties_size); + +bool power_supply_battery_info_has_prop(struct power_supply_battery_info *info, + enum power_supply_property psp) +{ + if (!info) + return false; + + switch (psp) { + case POWER_SUPPLY_PROP_TECHNOLOGY: + return info->technology != POWER_SUPPLY_TECHNOLOGY_UNKNOWN; + case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: + return info->energy_full_design_uwh >= 0; + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: + return info->charge_full_design_uah >= 0; + case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: + return info->voltage_min_design_uv >= 0; + case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: + return info->voltage_max_design_uv >= 0; + case POWER_SUPPLY_PROP_PRECHARGE_CURRENT: + return info->precharge_current_ua >= 0; + case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: + return info->charge_term_current_ua >= 0; + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: + return info->constant_charge_current_max_ua >= 0; + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: + return info->constant_charge_voltage_max_uv >= 0; + case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN: + return info->temp_ambient_alert_min > INT_MIN; + case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX: + return info->temp_ambient_alert_max < INT_MAX; + case POWER_SUPPLY_PROP_TEMP_ALERT_MIN: + return info->temp_alert_min > INT_MIN; + case POWER_SUPPLY_PROP_TEMP_ALERT_MAX: + return info->temp_alert_max < INT_MAX; + case POWER_SUPPLY_PROP_TEMP_MIN: + return info->temp_min > INT_MIN; + case POWER_SUPPLY_PROP_TEMP_MAX: + return info->temp_max < INT_MAX; + default: + return false; + } +} +EXPORT_SYMBOL_GPL(power_supply_battery_info_has_prop); + +int power_supply_battery_info_get_prop(struct power_supply_battery_info *info, + enum power_supply_property psp, + union power_supply_propval *val) +{ + if (!info) + return -EINVAL; + + if (!power_supply_battery_info_has_prop(info, psp)) + return -EINVAL; + + switch (psp) { + case POWER_SUPPLY_PROP_TECHNOLOGY: + val->intval = info->technology; + return 0; + case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: + val->intval = info->energy_full_design_uwh; + return 0; + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: + val->intval = info->charge_full_design_uah; + return 0; + case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: + val->intval = info->voltage_min_design_uv; + return 0; + case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: + val->intval = info->voltage_max_design_uv; + return 0; + case POWER_SUPPLY_PROP_PRECHARGE_CURRENT: + val->intval = info->precharge_current_ua; + return 0; + case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: + val->intval = info->charge_term_current_ua; + return 0; + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: + val->intval = info->constant_charge_current_max_ua; + return 0; + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: + val->intval = info->constant_charge_voltage_max_uv; + return 0; + case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN: + val->intval = info->temp_ambient_alert_min; + return 0; + case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX: + val->intval = info->temp_ambient_alert_max; + return 0; + case POWER_SUPPLY_PROP_TEMP_ALERT_MIN: + val->intval = info->temp_alert_min; + return 0; + case POWER_SUPPLY_PROP_TEMP_ALERT_MAX: + val->intval = info->temp_alert_max; + return 0; + case POWER_SUPPLY_PROP_TEMP_MIN: + val->intval = info->temp_min; + return 0; + case POWER_SUPPLY_PROP_TEMP_MAX: + val->intval = info->temp_max; + return 0; + default: + return -EINVAL; + } +} +EXPORT_SYMBOL_GPL(power_supply_battery_info_get_prop); + /** * power_supply_temp2resist_simple() - find the battery internal resistance * percent from temperature @@ -1046,6 +1173,22 @@ bool power_supply_battery_bti_in_range(struct power_supply_battery_info *info, } EXPORT_SYMBOL_GPL(power_supply_battery_bti_in_range); +static bool psy_has_property(const struct power_supply_desc *psy_desc, + enum power_supply_property psp) +{ + bool found = false; + int i; + + for (i = 0; i < psy_desc->num_properties; i++) { + if (psy_desc->properties[i] == psp) { + found = true; + break; + } + } + + return found; +} + int power_supply_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -1056,7 +1199,12 @@ int power_supply_get_property(struct power_supply *psy, return -ENODEV; } - return psy->desc->get_property(psy, psp, val); + if (psy_has_property(psy->desc, psp)) + return psy->desc->get_property(psy, psp, val); + else if (power_supply_battery_info_has_prop(psy->battery_info, psp)) + return power_supply_battery_info_get_prop(psy->battery_info, psp, val); + else + return -EINVAL; } EXPORT_SYMBOL_GPL(power_supply_get_property); @@ -1117,22 +1265,6 @@ void power_supply_unreg_notifier(struct notifier_block *nb) } EXPORT_SYMBOL_GPL(power_supply_unreg_notifier); -static bool psy_has_property(const struct power_supply_desc *psy_desc, - enum power_supply_property psp) -{ - bool found = false; - int i; - - for (i = 0; i < psy_desc->num_properties; i++) { - if (psy_desc->properties[i] == psp) { - found = true; - break; - } - } - - return found; -} - #ifdef CONFIG_THERMAL static int power_supply_read_temp(struct thermal_zone_device *tzd, int *temp) @@ -1255,6 +1387,11 @@ __power_supply_register(struct device *parent, goto check_supplies_failed; } + /* psy->battery_info is optional */ + rc = power_supply_get_battery_info(psy, &psy->battery_info); + if (rc && rc != -ENODEV) + goto check_supplies_failed; + spin_lock_init(&psy->changed_lock); rc = device_add(dev); if (rc) diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c index c228205e0953..5842dfe5dfb7 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -380,6 +380,9 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj, } } + if (power_supply_battery_info_has_prop(psy->battery_info, attrno)) + return mode; + return 0; } @@ -461,6 +464,8 @@ static int add_prop_uevent(const struct device *dev, struct kobj_uevent_env *env int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env) { const struct power_supply *psy = dev_get_drvdata(dev); + const enum power_supply_property *battery_props = + power_supply_battery_info_properties; int ret = 0, j; char *prop_buf; @@ -488,6 +493,16 @@ int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env) goto out; } + for (j = 0; j < power_supply_battery_info_properties_size; j++) { + if (!power_supply_battery_info_has_prop(psy->battery_info, + battery_props[j])) + continue; + ret = add_prop_uevent(dev, env, battery_props[j], + prop_buf); + if (ret) + goto out; + } + out: free_page((unsigned long)prop_buf); diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index aa2c4a7c4826..a427f13c757f 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -301,6 +301,7 @@ struct power_supply { bool initialized; bool removing; atomic_t use_cnt; + struct power_supply_battery_info *battery_info; #ifdef CONFIG_THERMAL struct thermal_zone_device *tzd; struct thermal_cooling_device *tcd; @@ -791,10 +792,17 @@ 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; extern int power_supply_get_battery_info(struct power_supply *psy, struct power_supply_battery_info **info_out); extern void power_supply_put_battery_info(struct power_supply *psy, struct power_supply_battery_info *info); +extern bool power_supply_battery_info_has_prop(struct power_supply_battery_info *info, + enum power_supply_property psp); +extern int power_supply_battery_info_get_prop(struct power_supply_battery_info *info, + enum power_supply_property psp, + union power_supply_propval *val); extern int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table, int table_len, int ocv); extern struct power_supply_battery_ocv_table * From patchwork Tue Mar 14 22:55:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13175103 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 3AF4CC761A6 for ; Tue, 14 Mar 2023 22:55:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231365AbjCNWzp (ORCPT ); Tue, 14 Mar 2023 18:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231287AbjCNWzo (ORCPT ); Tue, 14 Mar 2023 18:55:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94ECF39BA6; Tue, 14 Mar 2023 15:55:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4DCFEB81C00; Tue, 14 Mar 2023 22:55:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB73FC433A0; Tue, 14 Mar 2023 22:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678834539; bh=sgSRwxAxEIt1lhIpJ4LJp0jSf1yP+vzoOjDmNYSjqw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d6ObpYB1VMF2X1FRiFxslDZwJtNVbOz553I5Gw+66sl6srSRkko17jpmaTfM/0ino ItNUr8SonfFaSs7BKOu5O15n0GeCMRmh2rSGJiLgA4VW0utJF8L+/uioHlv9N5PH8d nm715S43A1+s3SBfB9/FphXlhhLG5PWhYK6WiJqG6UlnXQbWN39FtbkYx+k5hC1MwP 6cH5Tr+fknLKTXynJwNjtOI7mEA0OiLhkI7CmrlAjDK/udPVtkVbBtPA7gOAhb8vW7 7Vi54gjQ3QfjjZp1ooDdd7xQ0IsFH+3SyUzpBfUc1alqY/qKZxzZbbij6AWhesxmZK 5taDRPdwIsfzQ== Received: by mercury (Postfix, from userid 1000) id D686C10620A4; Tue, 14 Mar 2023 23:55:36 +0100 (CET) From: Sebastian Reichel To: Sebastian Reichel Cc: Linus Walleij , Matti Vaittinen , Rob Herring , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCHv2 03/12] power: supply: generic-adc-battery: convert to managed resources Date: Tue, 14 Mar 2023 23:55:26 +0100 Message-Id: <20230314225535.1321736-4-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314225535.1321736-1-sre@kernel.org> References: <20230314225535.1321736-1-sre@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Convert driver to use managed resources to simplify driver code. Reviewed-by: Linus Walleij Reviewed-by: Matti Vaittinen Signed-off-by: Sebastian Reichel --- drivers/power/supply/generic-adc-battery.c | 81 ++++++---------------- 1 file changed, 23 insertions(+), 58 deletions(-) diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c index 66039c665dd1..917bd2a6cc52 100644 --- a/drivers/power/supply/generic-adc-battery.c +++ b/drivers/power/supply/generic-adc-battery.c @@ -23,6 +23,7 @@ #include #include #include +#include #define JITTER_DEFAULT 10 /* hope 10ms is enough */ @@ -266,14 +267,13 @@ static int gab_probe(struct platform_device *pdev) * copying the static properties and allocating extra memory for holding * the extra configurable properties received from platform data. */ - properties = kcalloc(ARRAY_SIZE(gab_props) + - ARRAY_SIZE(gab_chan_name), - sizeof(*properties), - GFP_KERNEL); - if (!properties) { - ret = -ENOMEM; - goto first_mem_fail; - } + properties = devm_kcalloc(&pdev->dev, + ARRAY_SIZE(gab_props) + + ARRAY_SIZE(gab_chan_name), + sizeof(*properties), + GFP_KERNEL); + if (!properties) + return -ENOMEM; memcpy(properties, gab_props, sizeof(gab_props)); @@ -282,12 +282,13 @@ static int gab_probe(struct platform_device *pdev) * based on the channel supported by consumer device. */ for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) { - adc_bat->channel[chan] = iio_channel_get(&pdev->dev, - gab_chan_name[chan]); + adc_bat->channel[chan] = devm_iio_channel_get(&pdev->dev, gab_chan_name[chan]); if (IS_ERR(adc_bat->channel[chan])) { ret = PTR_ERR(adc_bat->channel[chan]); + if (ret != -ENODEV) + return dev_err_probe(&pdev->dev, ret, "Failed to get ADC channel %s\n", gab_chan_name[chan]); adc_bat->channel[chan] = NULL; - } else { + } else if (adc_bat->channel[chan]) { /* copying properties for supported channels only */ int index2; @@ -302,10 +303,8 @@ static int gab_probe(struct platform_device *pdev) } /* none of the channels are supported so let's bail out */ - if (!any) { - ret = -ENODEV; - goto second_mem_fail; - } + if (!any) + return dev_err_probe(&pdev->dev, -ENODEV, "Failed to get any ADC channel\n"); /* * Total number of properties is equal to static properties @@ -316,25 +315,24 @@ static int gab_probe(struct platform_device *pdev) psy_desc->properties = properties; psy_desc->num_properties = index; - adc_bat->psy = power_supply_register(&pdev->dev, psy_desc, &psy_cfg); - if (IS_ERR(adc_bat->psy)) { - ret = PTR_ERR(adc_bat->psy); - goto err_reg_fail; - } + adc_bat->psy = devm_power_supply_register(&pdev->dev, psy_desc, &psy_cfg); + if (IS_ERR(adc_bat->psy)) + return dev_err_probe(&pdev->dev, PTR_ERR(adc_bat->psy), "Failed to register power-supply device\n"); - INIT_DELAYED_WORK(&adc_bat->bat_work, gab_work); + ret = devm_delayed_work_autocancel(&pdev->dev, &adc_bat->bat_work, gab_work); + if (ret) + return dev_err_probe(&pdev->dev, ret, "Failed to register delayed work\n"); - adc_bat->charge_finished = devm_gpiod_get_optional(&pdev->dev, - "charged", GPIOD_IN); + adc_bat->charge_finished = devm_gpiod_get_optional(&pdev->dev, "charged", GPIOD_IN); if (adc_bat->charge_finished) { int irq; irq = gpiod_to_irq(adc_bat->charge_finished); - ret = request_any_context_irq(irq, gab_charged, + ret = devm_request_any_context_irq(&pdev->dev, irq, gab_charged, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "battery charged", adc_bat); if (ret < 0) - goto gpio_req_fail; + return dev_err_probe(&pdev->dev, ret, "Failed to register irq\n"); } platform_set_drvdata(pdev, adc_bat); @@ -343,38 +341,6 @@ static int gab_probe(struct platform_device *pdev) schedule_delayed_work(&adc_bat->bat_work, msecs_to_jiffies(0)); return 0; - -gpio_req_fail: - power_supply_unregister(adc_bat->psy); -err_reg_fail: - for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) { - if (adc_bat->channel[chan]) - iio_channel_release(adc_bat->channel[chan]); - } -second_mem_fail: - kfree(properties); -first_mem_fail: - return ret; -} - -static int gab_remove(struct platform_device *pdev) -{ - int chan; - struct gab *adc_bat = platform_get_drvdata(pdev); - - power_supply_unregister(adc_bat->psy); - - if (adc_bat->charge_finished) - free_irq(gpiod_to_irq(adc_bat->charge_finished), adc_bat); - - for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) { - if (adc_bat->channel[chan]) - iio_channel_release(adc_bat->channel[chan]); - } - - kfree(adc_bat->psy_desc.properties); - cancel_delayed_work_sync(&adc_bat->bat_work); - return 0; } static int __maybe_unused gab_suspend(struct device *dev) @@ -408,7 +374,6 @@ static struct platform_driver gab_driver = { .pm = &gab_pm_ops, }, .probe = gab_probe, - .remove = gab_remove, }; module_platform_driver(gab_driver); From patchwork Tue Mar 14 22:55:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13175100 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 0FAF2C76195 for ; Tue, 14 Mar 2023 22:55:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231334AbjCNWzo (ORCPT ); Tue, 14 Mar 2023 18:55:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231162AbjCNWzn (ORCPT ); Tue, 14 Mar 2023 18:55:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9278F39287; Tue, 14 Mar 2023 15:55:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 29F6CB81BFC; Tue, 14 Mar 2023 22:55:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E536C4339B; Tue, 14 Mar 2023 22:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678834539; bh=35QN0bzeY/9nc3m2KusNIkEd3B6r2Kv+UZyBrvNelB4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mDwGM+G/X24ezRvdHhqJ7xrox/Qhgn526cw5U7Goc9Qjik18wDD96rSQm6LmeEx/O MctH8dMy3Kpa3CNI60F4HUtitObF97gKouMRPSBs9av5Hcjg0h1VEZeAphJughprS+ 8pRbOe8URkN7RGrJCJwl4I5Yx9z5ITFcwPmx1s3fXPU35i7v2ms96KDCb0B1yXNYTx mIwAhT75MxcrUuG/z67kFrBnbOaZCZmqCmgFi5RcV39+mc6IikyclukC4tM8xvCijN J1YZ01OC7ITgSFKs32fm8wlSLMe4xB+EnpD5FkqaicBxwZHpI3+W5YH2N4ai25fW3G 0jAzT3JKRWhQg== Received: by mercury (Postfix, from userid 1000) id D8EB110620A5; Tue, 14 Mar 2023 23:55:36 +0100 (CET) From: Sebastian Reichel To: Sebastian Reichel Cc: Linus Walleij , Matti Vaittinen , Rob Herring , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCHv2 04/12] power: supply: generic-adc-battery: fix unit scaling Date: Tue, 14 Mar 2023 23:55:27 +0100 Message-Id: <20230314225535.1321736-5-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314225535.1321736-1-sre@kernel.org> References: <20230314225535.1321736-1-sre@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org power-supply properties are reported in µV, µA and µW. The IIO API provides mV, mA, mW, so the values need to be multiplied by 1000. Fixes: e60fea794e6e ("power: battery: Generic battery driver using IIO") Reviewed-by: Linus Walleij Reviewed-by: Matti Vaittinen Signed-off-by: Sebastian Reichel --- drivers/power/supply/generic-adc-battery.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c index 917bd2a6cc52..535972a332b3 100644 --- a/drivers/power/supply/generic-adc-battery.c +++ b/drivers/power/supply/generic-adc-battery.c @@ -136,6 +136,9 @@ static int read_channel(struct gab *adc_bat, enum power_supply_property psp, result); if (ret < 0) pr_err("read channel error\n"); + else + *result *= 1000; + return ret; } From patchwork Tue Mar 14 22:55:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13175106 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 C29F0C76195 for ; Tue, 14 Mar 2023 22:55:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231467AbjCNWz4 (ORCPT ); Tue, 14 Mar 2023 18:55:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231387AbjCNWzr (ORCPT ); Tue, 14 Mar 2023 18:55:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8E523B3C7; Tue, 14 Mar 2023 15:55:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 27392B81BFE; Tue, 14 Mar 2023 22:55:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72C97C433A1; Tue, 14 Mar 2023 22:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678834542; bh=cBF4sj28SAckbtk/zdaRv0Kn7wKLfTnCwzHMWh0YXEs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JSU7DaNXy//9n25Kep6euafARySKRNhYkaS5noSXnOttdpvYBy1RmI/l3RV05OK5z /sb3jg7+17oWT/ABlT/YP6lpOqLpkd0TCd/rvWC9NBMnQn4HPmK5jP1KJ0rHMjUikE JpD6XP4d82wQmpACJDPOCeYFkb5lo7rPGDWa6DIn4zGDDfnvk6HsUX/TpE3PZu7P0b 1wf4ZbNHNVz/YlAkHLt8swCkm2xdrhTEwkA+mTP1zQhYXlHCk0fhCiGVTFn5hpS8hL 26Z7ZxSS5NRPSxH6yNg30Xtpj3SrzklzRyXKuzECkepAFAaVSnJYLohe0hEPhPxUHh +1hLvgnI7vPzA== Received: by mercury (Postfix, from userid 1000) id DB50510620A7; Tue, 14 Mar 2023 23:55:36 +0100 (CET) From: Sebastian Reichel To: Sebastian Reichel Cc: Linus Walleij , Matti Vaittinen , Rob Herring , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCHv2 05/12] power: supply: generic-adc-battery: drop jitter delay support Date: Tue, 14 Mar 2023 23:55:28 +0100 Message-Id: <20230314225535.1321736-6-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314225535.1321736-1-sre@kernel.org> References: <20230314225535.1321736-1-sre@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Drop support for configuring IRQ jitter delay by using big enough fixed value. Reviewed-by: Linus Walleij Signed-off-by: Sebastian Reichel --- drivers/power/supply/generic-adc-battery.c | 13 ++++--------- include/linux/power/generic-adc-battery.h | 3 --- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c index 535972a332b3..e20894460d7f 100644 --- a/drivers/power/supply/generic-adc-battery.c +++ b/drivers/power/supply/generic-adc-battery.c @@ -227,12 +227,10 @@ static void gab_work(struct work_struct *work) static irqreturn_t gab_charged(int irq, void *dev_id) { struct gab *adc_bat = dev_id; - struct gab_platform_data *pdata = adc_bat->pdata; - int delay; - delay = pdata->jitter_delay ? pdata->jitter_delay : JITTER_DEFAULT; schedule_delayed_work(&adc_bat->bat_work, - msecs_to_jiffies(delay)); + msecs_to_jiffies(JITTER_DEFAULT)); + return IRQ_HANDLED; } @@ -358,14 +356,11 @@ static int __maybe_unused gab_suspend(struct device *dev) static int __maybe_unused gab_resume(struct device *dev) { struct gab *adc_bat = dev_get_drvdata(dev); - struct gab_platform_data *pdata = adc_bat->pdata; - int delay; - - delay = pdata->jitter_delay ? pdata->jitter_delay : JITTER_DEFAULT; /* Schedule timer to check current status */ schedule_delayed_work(&adc_bat->bat_work, - msecs_to_jiffies(delay)); + msecs_to_jiffies(JITTER_DEFAULT)); + return 0; } diff --git a/include/linux/power/generic-adc-battery.h b/include/linux/power/generic-adc-battery.h index c68cbf34cd34..50eb4bf28286 100644 --- a/include/linux/power/generic-adc-battery.h +++ b/include/linux/power/generic-adc-battery.h @@ -11,13 +11,10 @@ * @battery_info: recommended structure to specify static power supply * parameters * @cal_charge: calculate charge level. - * @jitter_delay: delay required after the interrupt to check battery - * status.Default set is 10ms. */ struct gab_platform_data { struct power_supply_info battery_info; int (*cal_charge)(long value); - int jitter_delay; }; #endif /* GENERIC_ADC_BATTERY_H */ From patchwork Tue Mar 14 22:55:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13175105 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 A60E1C7618B for ; Tue, 14 Mar 2023 22:55:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231428AbjCNWzy (ORCPT ); Tue, 14 Mar 2023 18:55:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231382AbjCNWzr (ORCPT ); Tue, 14 Mar 2023 18:55:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 349F83E612; Tue, 14 Mar 2023 15:55:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E7615B81C05; Tue, 14 Mar 2023 22:55:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 727D9C4339C; Tue, 14 Mar 2023 22:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678834542; bh=c3WYbgfatFUXlt2kUOofkHvWoKbgirGFc4A+gjyj7bE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qtzCl7gYSVKutZ0CjQ9hz602o3x9g6IBNhTepY6xuJd52CDkM+nWFzcbE+Wra85Kh VRDoeLaopJWOxW3M0MLfwBOZaqYZia0ng2rFvDkVEKIz8OCo5Cxdld7E05eDyCGtq4 VuHvn3XjjH57oIGW9NJCZLfcTQ33leOjauywTZzBfiLsDa2+FGLqrtC+vt/ylDIil5 6WSWSFi0V31lAm7qoIMchk20inV5S96bVztT0D/sGBhAyUH09Db9rxlYSXeDlZW26q tR2zgRflxuzfpkbq8YfIUc8umv3OTBz8XjLIGMmMWp53uM4xnSurzjjY1t+es/rikq U6mqCwYPxkRUw== Received: by mercury (Postfix, from userid 1000) id DDAF510620A9; Tue, 14 Mar 2023 23:55:36 +0100 (CET) From: Sebastian Reichel To: Sebastian Reichel Cc: Linus Walleij , Matti Vaittinen , Rob Herring , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCHv2 06/12] power: supply: generic-adc-battery: drop charge now support Date: Tue, 14 Mar 2023 23:55:29 +0100 Message-Id: <20230314225535.1321736-7-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314225535.1321736-1-sre@kernel.org> References: <20230314225535.1321736-1-sre@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Drop CHARGE_NOW support, which requires a platform specific calculation method. Reviewed-by: Linus Walleij Reviewed-by: Matti Vaittinen Signed-off-by: Sebastian Reichel --- drivers/power/supply/generic-adc-battery.c | 4 ---- include/linux/power/generic-adc-battery.h | 2 -- 2 files changed, 6 deletions(-) diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c index e20894460d7f..d07eeb7d46d3 100644 --- a/drivers/power/supply/generic-adc-battery.c +++ b/drivers/power/supply/generic-adc-battery.c @@ -72,7 +72,6 @@ static const enum power_supply_property gab_props[] = { POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN, - POWER_SUPPLY_PROP_CHARGE_NOW, POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_TECHNOLOGY, @@ -166,9 +165,6 @@ static int gab_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN: val->intval = 0; break; - case POWER_SUPPLY_PROP_CHARGE_NOW: - val->intval = pdata->cal_charge(result); - break; case POWER_SUPPLY_PROP_VOLTAGE_NOW: case POWER_SUPPLY_PROP_CURRENT_NOW: case POWER_SUPPLY_PROP_POWER_NOW: diff --git a/include/linux/power/generic-adc-battery.h b/include/linux/power/generic-adc-battery.h index 50eb4bf28286..54434e4304d3 100644 --- a/include/linux/power/generic-adc-battery.h +++ b/include/linux/power/generic-adc-battery.h @@ -10,11 +10,9 @@ * struct gab_platform_data - platform_data for generic adc iio battery driver. * @battery_info: recommended structure to specify static power supply * parameters - * @cal_charge: calculate charge level. */ struct gab_platform_data { struct power_supply_info battery_info; - int (*cal_charge)(long value); }; #endif /* GENERIC_ADC_BATTERY_H */ From patchwork Tue Mar 14 22:55:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13175108 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 9D7D8C7618B for ; Tue, 14 Mar 2023 22:55:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230402AbjCNWz4 (ORCPT ); Tue, 14 Mar 2023 18:55:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231370AbjCNWzr (ORCPT ); Tue, 14 Mar 2023 18:55:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A9523E60D; Tue, 14 Mar 2023 15:55:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D2255B81BFD; Tue, 14 Mar 2023 22:55:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71978C4339B; Tue, 14 Mar 2023 22:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678834542; bh=yPzVoyb/Gfy3GbgXbS/xEPN0qDCVRKIVaWj3y97xOno=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dbkrJl8Um/67y1V8O9IC2TYKYe9FNx3Etd6CgWjefe353hRY6L6/jx/ng9EIre2Mo d/kjROV1i/Z1PRej2poOfRwXOuN0MhSWvtAzfAPYC9/74dplgETKRveYRygyuYo5kQ ZliBzSJLNn3T3HBsCwW0IBCRW9OXgS+Tw8kyJp1N83HPOW0lsC7jOJbzluBqefZGBW NsNid6xSPJxWAeHHBenfWjUiti99lkD5NomB9UZRqHqBa0QNgM7w7UHp3VoWXamuhu weIQ04dR6YdTDK1lS3IbbGr0KbE19wehMgrmH/ohGsjSFBadiXtZGejrd+62J36A66 q/vLvFzkMnEOQ== Received: by mercury (Postfix, from userid 1000) id DFE5210620AA; Tue, 14 Mar 2023 23:55:36 +0100 (CET) From: Sebastian Reichel To: Sebastian Reichel Cc: Linus Walleij , Matti Vaittinen , Rob Herring , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCHv2 07/12] power: supply: generic-adc-battery: drop memory alloc error message Date: Tue, 14 Mar 2023 23:55:30 +0100 Message-Id: <20230314225535.1321736-8-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314225535.1321736-1-sre@kernel.org> References: <20230314225535.1321736-1-sre@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Error printing happens automatically for memory allocation problems. Reviewed-by: Linus Walleij Reviewed-by: Matti Vaittinen Signed-off-by: Sebastian Reichel --- drivers/power/supply/generic-adc-battery.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c index d07eeb7d46d3..771e5cfc49c3 100644 --- a/drivers/power/supply/generic-adc-battery.c +++ b/drivers/power/supply/generic-adc-battery.c @@ -243,10 +243,8 @@ static int gab_probe(struct platform_device *pdev) bool any = false; adc_bat = devm_kzalloc(&pdev->dev, sizeof(*adc_bat), GFP_KERNEL); - if (!adc_bat) { - dev_err(&pdev->dev, "failed to allocate memory\n"); + if (!adc_bat) return -ENOMEM; - } psy_cfg.drv_data = adc_bat; psy_desc = &adc_bat->psy_desc; From patchwork Tue Mar 14 22:55:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13175111 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 35A0AC7618D for ; Tue, 14 Mar 2023 22:56:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231487AbjCNW4D (ORCPT ); Tue, 14 Mar 2023 18:56:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231459AbjCNWz4 (ORCPT ); Tue, 14 Mar 2023 18:55:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABDEF43937; Tue, 14 Mar 2023 15:55:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3D281B81BFF; Tue, 14 Mar 2023 22:55:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F31DC433A4; Tue, 14 Mar 2023 22:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678834542; bh=7YH4QVgz1Riw28ilrhLvb611eMg8DgBLWjF4R5j+F+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uzaj6+L/XgEC68aIwxz2Vl/a7Aj2up35lbcaYzrPztTeuIMoCXypfI4a+3Ge3mKcQ xJclpmvYlkCrvw2X6CQBih4r4bjaLTCyTqq3AXY6yz1yiplLYD646gqtVPOS/OPqEX Jjmqq1QZGxDW8GkghWDX5EPVM0WyKUkHk+2GjtE1SNU/lMXpZn/36lGczDnjun6L2b AyyBHPsiAUXpPSNpIv2boNWDJWATo6ZwDCT0DJORZEUxEGD/Q5ecJhgNWK/onpHxfb HGjyr5k0LxmaqLABKhYY8Gfv2W+8zYPFHBHw7rYZYr8QMUueaJ/UXu6OMFRnlXpoDP V/TeANnfMSacw== Received: by mercury (Postfix, from userid 1000) id E33EF10620AB; Tue, 14 Mar 2023 23:55:36 +0100 (CET) From: Sebastian Reichel To: Sebastian Reichel Cc: Linus Walleij , Matti Vaittinen , Rob Herring , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCHv2 08/12] power: supply: generic-adc-battery: use simple-battery API Date: Tue, 14 Mar 2023 23:55:31 +0100 Message-Id: <20230314225535.1321736-9-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314225535.1321736-1-sre@kernel.org> References: <20230314225535.1321736-1-sre@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Use standard simple-battery API for constant battery information like min and max voltage. This simplifies the driver a lot and brings automatic support for DT. Reviewed-by: Linus Walleij Signed-off-by: Sebastian Reichel --- drivers/power/supply/generic-adc-battery.c | 64 ++-------------------- include/linux/power/generic-adc-battery.h | 18 ------ 2 files changed, 4 insertions(+), 78 deletions(-) delete mode 100644 include/linux/power/generic-adc-battery.h diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c index 771e5cfc49c3..d4f63d945b2c 100644 --- a/drivers/power/supply/generic-adc-battery.c +++ b/drivers/power/supply/generic-adc-battery.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #define JITTER_DEFAULT 10 /* hope 10ms is enough */ @@ -48,9 +47,7 @@ struct gab { struct power_supply *psy; struct power_supply_desc psy_desc; struct iio_channel *channel[GAB_MAX_CHAN_TYPE]; - struct gab_platform_data *pdata; struct delayed_work bat_work; - int level; int status; bool cable_plugged; struct gpio_desc *charge_finished; @@ -70,14 +67,6 @@ static void gab_ext_power_changed(struct power_supply *psy) static const enum power_supply_property gab_props[] = { POWER_SUPPLY_PROP_STATUS, - POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, - POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN, - POWER_SUPPLY_PROP_VOLTAGE_NOW, - POWER_SUPPLY_PROP_CURRENT_NOW, - POWER_SUPPLY_PROP_TECHNOLOGY, - POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, - POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, - POWER_SUPPLY_PROP_MODEL_NAME, }; /* @@ -97,17 +86,6 @@ static bool gab_charge_finished(struct gab *adc_bat) return gpiod_get_value(adc_bat->charge_finished); } -static int gab_get_status(struct gab *adc_bat) -{ - struct gab_platform_data *pdata = adc_bat->pdata; - struct power_supply_info *bat_info; - - bat_info = &pdata->battery_info; - if (adc_bat->level == bat_info->charge_full_design) - return POWER_SUPPLY_STATUS_FULL; - return adc_bat->status; -} - static enum gab_chan_type gab_prop_to_chan(enum power_supply_property psp) { switch (psp) { @@ -144,27 +122,12 @@ static int read_channel(struct gab *adc_bat, enum power_supply_property psp, static int gab_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { - struct gab *adc_bat; - struct gab_platform_data *pdata; - struct power_supply_info *bat_info; - int result = 0; - int ret = 0; - - adc_bat = to_generic_bat(psy); - if (!adc_bat) { - dev_err(&psy->dev, "no battery infos ?!\n"); - return -EINVAL; - } - pdata = adc_bat->pdata; - bat_info = &pdata->battery_info; + struct gab *adc_bat = to_generic_bat(psy); switch (psp) { case POWER_SUPPLY_PROP_STATUS: - val->intval = gab_get_status(adc_bat); - break; - case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN: - val->intval = 0; - break; + val->intval = adc_bat->status; + return 0; case POWER_SUPPLY_PROP_VOLTAGE_NOW: case POWER_SUPPLY_PROP_CURRENT_NOW: case POWER_SUPPLY_PROP_POWER_NOW: @@ -173,26 +136,9 @@ static int gab_get_property(struct power_supply *psy, goto err; val->intval = result; break; - case POWER_SUPPLY_PROP_TECHNOLOGY: - val->intval = bat_info->technology; - break; - case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: - val->intval = bat_info->voltage_min_design; - break; - case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: - val->intval = bat_info->voltage_max_design; - break; - case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: - val->intval = bat_info->charge_full_design; - break; - case POWER_SUPPLY_PROP_MODEL_NAME: - val->strval = bat_info->name; - break; default: return -EINVAL; } -err: - return ret; } static void gab_work(struct work_struct *work) @@ -235,7 +181,6 @@ static int gab_probe(struct platform_device *pdev) struct gab *adc_bat; struct power_supply_desc *psy_desc; struct power_supply_config psy_cfg = {}; - struct gab_platform_data *pdata = pdev->dev.platform_data; enum power_supply_property *properties; int ret = 0; int chan; @@ -248,7 +193,7 @@ static int gab_probe(struct platform_device *pdev) psy_cfg.drv_data = adc_bat; psy_desc = &adc_bat->psy_desc; - psy_desc->name = pdata->battery_info.name; + psy_desc->name = dev_name(&pdev->dev); /* bootup default values for the battery */ adc_bat->cable_plugged = false; @@ -256,7 +201,6 @@ static int gab_probe(struct platform_device *pdev) psy_desc->type = POWER_SUPPLY_TYPE_BATTERY; psy_desc->get_property = gab_get_property; psy_desc->external_power_changed = gab_ext_power_changed; - adc_bat->pdata = pdata; /* * copying the static properties and allocating extra memory for holding diff --git a/include/linux/power/generic-adc-battery.h b/include/linux/power/generic-adc-battery.h deleted file mode 100644 index 54434e4304d3..000000000000 --- a/include/linux/power/generic-adc-battery.h +++ /dev/null @@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2012, Anish Kumar - */ - -#ifndef GENERIC_ADC_BATTERY_H -#define GENERIC_ADC_BATTERY_H - -/** - * struct gab_platform_data - platform_data for generic adc iio battery driver. - * @battery_info: recommended structure to specify static power supply - * parameters - */ -struct gab_platform_data { - struct power_supply_info battery_info; -}; - -#endif /* GENERIC_ADC_BATTERY_H */ From patchwork Tue Mar 14 22:55:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13175110 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 1F4E3C761AF for ; Tue, 14 Mar 2023 22:56:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231484AbjCNW4A (ORCPT ); Tue, 14 Mar 2023 18:56:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbjCNWzz (ORCPT ); Tue, 14 Mar 2023 18:55:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB67C43921; Tue, 14 Mar 2023 15:55:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3D26EB81BFA; Tue, 14 Mar 2023 22:55:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C3D2C433A8; Tue, 14 Mar 2023 22:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678834542; bh=owAvzfzmofpsvtSIDluD5S9OyIrSNEAKN3RrjH509gY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=upS5hAecnUVILWMTKeGJsX8SJnj8OZey8qg57ZmqrXNprUVy79kqat3bo/9hTCDwN O7gp6p7LJtt9VVy4rp49sb+PID3bT43izDMm28bN8G2LcFhlttolSbo2gL75sSGcnv VmcwbfSDHHVeBKOeQrony3ewrHqizCuaj/+JPyZXxf5ctX9scdwtDUqziHoLcueAkZ 7eDIinVPS6z1+xIBy+vI0970UR8tgIRTCugKE4904K5gdef2BL16e1xLfwix5SKvVX V+2e5KgC74yIhhqeaNAF8Alunav5s/MnHNOum5zEsqu11k4nh+bIRG8RWEurp4N4hc IPTIemGfwB+Xg== Received: by mercury (Postfix, from userid 1000) id E476610620B0; Tue, 14 Mar 2023 23:55:36 +0100 (CET) From: Sebastian Reichel To: Sebastian Reichel Cc: Linus Walleij , Matti Vaittinen , Rob Herring , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCHv2 09/12] power: supply: generic-adc-battery: simplify read_channel logic Date: Tue, 14 Mar 2023 23:55:32 +0100 Message-Id: <20230314225535.1321736-10-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314225535.1321736-1-sre@kernel.org> References: <20230314225535.1321736-1-sre@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Drop mostly useless gab_prop_to_chan() function by directly supplying the correct enum value to read_channel(). Reviewed-by: Linus Walleij Reviewed-by: Matti Vaittinen Signed-off-by: Sebastian Reichel --- drivers/power/supply/generic-adc-battery.c | 31 ++++------------------ 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c index d4f63d945b2c..4811e72df8cd 100644 --- a/drivers/power/supply/generic-adc-battery.c +++ b/drivers/power/supply/generic-adc-battery.c @@ -86,31 +86,12 @@ static bool gab_charge_finished(struct gab *adc_bat) return gpiod_get_value(adc_bat->charge_finished); } -static enum gab_chan_type gab_prop_to_chan(enum power_supply_property psp) -{ - switch (psp) { - case POWER_SUPPLY_PROP_POWER_NOW: - return GAB_POWER; - case POWER_SUPPLY_PROP_VOLTAGE_NOW: - return GAB_VOLTAGE; - case POWER_SUPPLY_PROP_CURRENT_NOW: - return GAB_CURRENT; - default: - WARN_ON(1); - break; - } - return GAB_POWER; -} - -static int read_channel(struct gab *adc_bat, enum power_supply_property psp, +static int read_channel(struct gab *adc_bat, enum gab_chan_type channel, int *result) { int ret; - int chan_index; - chan_index = gab_prop_to_chan(psp); - ret = iio_read_channel_processed(adc_bat->channel[chan_index], - result); + ret = iio_read_channel_processed(adc_bat->channel[channel], result); if (ret < 0) pr_err("read channel error\n"); else @@ -129,13 +110,11 @@ static int gab_get_property(struct power_supply *psy, val->intval = adc_bat->status; return 0; case POWER_SUPPLY_PROP_VOLTAGE_NOW: + return read_channel(adc_bat, GAB_VOLTAGE, &val->intval); case POWER_SUPPLY_PROP_CURRENT_NOW: + return read_channel(adc_bat, GAB_CURRENT, &val->intval); case POWER_SUPPLY_PROP_POWER_NOW: - ret = read_channel(adc_bat, psp, &result); - if (ret < 0) - goto err; - val->intval = result; - break; + return read_channel(adc_bat, GAB_POWER, &val->intval); default: return -EINVAL; } From patchwork Tue Mar 14 22:55:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13175107 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 6E465C7618D for ; Tue, 14 Mar 2023 22:55:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231343AbjCNWz6 (ORCPT ); Tue, 14 Mar 2023 18:55:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231381AbjCNWzr (ORCPT ); Tue, 14 Mar 2023 18:55:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F8183E60F; Tue, 14 Mar 2023 15:55:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D674EB81C03; Tue, 14 Mar 2023 22:55:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70F89C433EF; Tue, 14 Mar 2023 22:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678834542; bh=TaqFMsF6uQPer7urWpXd+hD3bCoXdn3xFrMC/vSG5ks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WHHYd5al8ljAwEqeWDYM40QXnrc7ffF7s2o4EeVLwV2MKYPytThnCtVdkwnpchzVH dkxSgwMzQXSmFg3bUb/7Bvh93WqclU/v8bAE5qQJbLl0CtFoZXFt9kn8jzk1iWXOu+ +cp8Hxp+gTbJ+pSHn9DU3ZFPvy+yxV1Fnv64fbfW8sHrK3c72jbkNbbOtYwrfnomx+ lCDDD1udGsb2e6twARymFM5A/i0ZHSWt1LPRifVdbms0O1699UZn+HlnLOVaUqMlBO K4Mieoa1td+arnYC4aTUG7wFCeacrnCF3bwlMJnSABqM8w5ezfST+qmPRmJbrOZsSI /NsPs5/YvaBKg== Received: by mercury (Postfix, from userid 1000) id E6C0410620B1; Tue, 14 Mar 2023 23:55:36 +0100 (CET) From: Sebastian Reichel To: Sebastian Reichel Cc: Linus Walleij , Matti Vaittinen , Rob Herring , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, Sebastian Reichel Subject: [PATCHv2 10/12] power: supply: generic-adc-battery: add temperature support Date: Tue, 14 Mar 2023 23:55:33 +0100 Message-Id: <20230314225535.1321736-11-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314225535.1321736-1-sre@kernel.org> References: <20230314225535.1321736-1-sre@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Sebastian Reichel Another typical thing to monitor via an ADC line is the battery temperature. Signed-off-by: Sebastian Reichel Reviewed-by: Matti Vaittinen Reviewed-by: Linus Walleij --- drivers/power/supply/generic-adc-battery.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c index 4811e72df8cd..0124d8d51af7 100644 --- a/drivers/power/supply/generic-adc-battery.c +++ b/drivers/power/supply/generic-adc-battery.c @@ -30,6 +30,7 @@ enum gab_chan_type { GAB_VOLTAGE = 0, GAB_CURRENT, GAB_POWER, + GAB_TEMP, GAB_MAX_CHAN_TYPE }; @@ -40,7 +41,8 @@ enum gab_chan_type { static const char *const gab_chan_name[] = { [GAB_VOLTAGE] = "voltage", [GAB_CURRENT] = "current", - [GAB_POWER] = "power", + [GAB_POWER] = "power", + [GAB_TEMP] = "temperature", }; struct gab { @@ -77,6 +79,7 @@ static const enum power_supply_property gab_dyn_props[] = { POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_POWER_NOW, + POWER_SUPPLY_PROP_TEMP, }; static bool gab_charge_finished(struct gab *adc_bat) @@ -115,6 +118,8 @@ static int gab_get_property(struct power_supply *psy, return read_channel(adc_bat, GAB_CURRENT, &val->intval); case POWER_SUPPLY_PROP_POWER_NOW: return read_channel(adc_bat, GAB_POWER, &val->intval); + case POWER_SUPPLY_PROP_TEMP: + return read_channel(adc_bat, GAB_TEMP, &val->intval); default: return -EINVAL; } From patchwork Tue Mar 14 22:55:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13175104 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 DBD9FC6FD1D for ; Tue, 14 Mar 2023 22:55:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231400AbjCNWzr (ORCPT ); Tue, 14 Mar 2023 18:55:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230293AbjCNWzp (ORCPT ); Tue, 14 Mar 2023 18:55:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03B713D08E; Tue, 14 Mar 2023 15:55:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 91C0361A4E; Tue, 14 Mar 2023 22:55:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77C83C433D2; Tue, 14 Mar 2023 22:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678834542; bh=N/S690ZAfx+m44tSOvrZoNkOK1xJvdzfGkZgNi3dgws=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UvbWa7eCqEKLg4IJ91SFCgqT06tl3rTZuOkHyzTmVezFaPF+XoLLo1lp2ortT6Ng9 hMReff1R278albuSjAIppVpPwdEkj4bf8f2ZsM2aOUQHDicdHIXj8aFRqO/2g/iaMJ 73uVUvU/VgZR20pHK1idCgvBTLgt9mJtFR5t7dho8A2TK9a8MM1qsgawghgMSpBQ8A r52TPBf4XAQuRdJ20RyG5h49pEnd7j4A8+GpArIiZBa7b67UVXDTLfTGuFLa++zwXa 37m64E6p/zL1GQ4ufHlVl0U9STftDgVTdeTjfGu0un1OGCtJA/rDXkhqT7NQcPFiyU saD6SezaxHbNQ== Received: by mercury (Postfix, from userid 1000) id E93B810620B2; Tue, 14 Mar 2023 23:55:36 +0100 (CET) From: Sebastian Reichel To: Sebastian Reichel Cc: Linus Walleij , Matti Vaittinen , Rob Herring , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCHv2 11/12] power: supply: generic-adc-battery: add DT support Date: Tue, 14 Mar 2023 23:55:34 +0100 Message-Id: <20230314225535.1321736-12-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314225535.1321736-1-sre@kernel.org> References: <20230314225535.1321736-1-sre@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This adds full DT support to the driver. Because of the previous changes just adding a compatible value is enough. Reviewed-by: Linus Walleij Reviewed-by: Matti Vaittinen Signed-off-by: Sebastian Reichel --- drivers/power/supply/generic-adc-battery.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c index 0124d8d51af7..e11ad43ab968 100644 --- a/drivers/power/supply/generic-adc-battery.c +++ b/drivers/power/supply/generic-adc-battery.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #define JITTER_DEFAULT 10 /* hope 10ms is enough */ @@ -175,6 +176,7 @@ static int gab_probe(struct platform_device *pdev) if (!adc_bat) return -ENOMEM; + psy_cfg.of_node = pdev->dev.of_node; psy_cfg.drv_data = adc_bat; psy_desc = &adc_bat->psy_desc; psy_desc->name = dev_name(&pdev->dev); @@ -288,10 +290,17 @@ static int __maybe_unused gab_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(gab_pm_ops, gab_suspend, gab_resume); +static const struct of_device_id gab_match[] = { + { .compatible = "adc-battery" }, + { } +}; +MODULE_DEVICE_TABLE(of, gab_match); + static struct platform_driver gab_driver = { .driver = { .name = "generic-adc-battery", .pm = &gab_pm_ops, + .of_match_table = gab_match, }, .probe = gab_probe, }; From patchwork Tue Mar 14 22:55:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13175109 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 B2D00C76196 for ; Tue, 14 Mar 2023 22:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231391AbjCNWz7 (ORCPT ); Tue, 14 Mar 2023 18:55:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230338AbjCNWzx (ORCPT ); Tue, 14 Mar 2023 18:55:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 473A03B669; Tue, 14 Mar 2023 15:55:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E24CDB819C4; Tue, 14 Mar 2023 22:55:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72AABC4339E; Tue, 14 Mar 2023 22:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678834542; bh=YJYG6gviCQ9ScytyBdiyC20i5BbAe56kmhR8ux24MBU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ryWIvImJ/vgXiGcMGGSFElVHMPzphTZjywrJGuibCwFzutlGiufmVEaQZPTZbwwVv Cdl8C0Ri7eH8s8fIRsvWhmDlct7dLIHhXkLDCV8hNCFHed3dAN1wlJ7QD+1IZZAO9i rBUzBrtWfJMpzPuQddmyTNSD/gcz5x4fP1sXjZ6xy63GXhUdEQPafkc3Z/n1U5l7sQ E2KThaCkcoNhCZ2kbarVP0lQ7swAnPHvGM/YhYgxAvmvExa0h9pTqkgvT1fPhMNHCm u2JGKG5R+7hf+HNE/Ij9Yg7Ric4u9XUuUaio3GyMLsqW/AlktynawBg6nqV+n8huiU OnlstOdPZcSzg== Received: by mercury (Postfix, from userid 1000) id EBA0A10620B3; Tue, 14 Mar 2023 23:55:36 +0100 (CET) From: Sebastian Reichel To: Sebastian Reichel Cc: Linus Walleij , Matti Vaittinen , Rob Herring , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCHv2 12/12] power: supply: generic-adc-battery: update copyright info Date: Tue, 14 Mar 2023 23:55:35 +0100 Message-Id: <20230314225535.1321736-13-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314225535.1321736-1-sre@kernel.org> References: <20230314225535.1321736-1-sre@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org jz4740-battery.c and s3c_adc_battery.c have been removed from the tree and after all of my restructuring the driver is basically no longer based on them. Thus update the copyright information and switch to SPDX license identifier while being at it. Reviewed-by: Linus Walleij Reviewed-by: Matti Vaittinen Signed-off-by: Sebastian Reichel --- drivers/power/supply/generic-adc-battery.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c index e11ad43ab968..df1c0a1c6b52 100644 --- a/drivers/power/supply/generic-adc-battery.c +++ b/drivers/power/supply/generic-adc-battery.c @@ -1,13 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 /* - * Generic battery driver code using IIO + * Generic battery driver using IIO * Copyright (C) 2012, Anish Kumar - * based on jz4740-battery.c - * based on s3c_adc_battery.c - * - * This file is subject to the terms and conditions of the GNU General Public - * License. See the file COPYING in the main directory of this archive for - * more details. - * + * Copyright (c) 2023, Sebastian Reichel */ #include #include