From patchwork Thu Mar 9 22:50: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: 13168510 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 37037C61DA4 for ; Thu, 9 Mar 2023 22:50:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231290AbjCIWuy (ORCPT ); Thu, 9 Mar 2023 17:50:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230093AbjCIWux (ORCPT ); Thu, 9 Mar 2023 17:50:53 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5684BE841B; Thu, 9 Mar 2023 14:50:47 -0800 (PST) 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 D4A7B61D0E; Thu, 9 Mar 2023 22:50:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00744C4339B; Thu, 9 Mar 2023 22:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678402246; bh=T2m9FARCQakjOu5gGr8+fVrNfdOmvCfKaWsccO+YD5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gb6Gm1T2ILsdxCDVZETBEkU1XPniS+tw2i2tNvRHqWSHCtpDASlciuF7JlasIYztt KvMj1iQqzSILJeO2NLlftJyev3Z5qJsYTw07/Ioe6l+SYLP9+g333TZs9cnQkZn7xu IXPeRG0FM/ROcBW2+kKjJuBL+qXNPtXzCHMlo7+QMD+GySgKM4uO5ReEOCbE0cPSh5 OHSO38dbRsxYWThikticoYf6zSAxZO8sU116XvsOHayXMfwhz1RkNGC2cG1MgsOjie lzqpGaz/Cuo5sayivfXpNa7GOuSm9mXqq34nbmtPrLVx6Y2XozqJ/IMr4uKdcG7xtx 0RffqHMV4Rm0Q== Received: by mercury (Postfix, from userid 1000) id 6151C106069D; Thu, 9 Mar 2023 23:50:43 +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: [PATCHv1 01/11] dt-bindings: power: supply: adc-battery: add binding Date: Thu, 9 Mar 2023 23:50:31 +0100 Message-Id: <20230309225041.477440-2-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309225041.477440-1-sre@kernel.org> References: <20230309225041.477440-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 --- .../bindings/power/supply/adc-battery.yaml | 67 +++++++++++++++++++ 1 file changed, 67 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..9d478bf9d2ee --- /dev/null +++ b/Documentation/devicetree/bindings/power/supply/adc-battery.yaml @@ -0,0 +1,67 @@ +# 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, which only reports (in circuit) voltage and optionally + current via an ADC channel. + +allOf: + - $ref: power-supply.yaml# + +properties: + compatible: + const: adc-battery + + charged-gpios: + description: + GPIO which signals that the battery is fully charged. + maxItems: 1 + + io-channels: + minItems: 1 + maxItems: 3 + + io-channel-names: + oneOf: + - const: voltage + - items: + - const: voltage + - enum: + - current + - power + - items: + - const: voltage + - const: current + - const: power + + 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 Thu Mar 9 22:50: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: 13168513 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 96EC1C64EC4 for ; Thu, 9 Mar 2023 22:50:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231394AbjCIWu4 (ORCPT ); Thu, 9 Mar 2023 17:50:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230395AbjCIWuy (ORCPT ); Thu, 9 Mar 2023 17:50:54 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56B42F7EDF; Thu, 9 Mar 2023 14:50:47 -0800 (PST) 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 D504761D1B; Thu, 9 Mar 2023 22:50:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08484C433A0; Thu, 9 Mar 2023 22:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678402246; bh=SSBVCBpnRcjlaOW5Jpyryn0OebgyhMRXGKYdYC08d4g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ggD2TpUNdKuqny1/UKbyn+8N0vRnG+9UDxQHS8Ikarfk/iN06DFQx/jDhdaKAgQ81 UBIHMhfhW9HGWAZuepg+zsNxjOkjQ/3p4cDiaO9AUZGHIeOkRCFy3qTZuETy0epfvJ gLFhKxhXCtsI44Z3nabAVUZ28b66nqO55CtuSjp6wbZ9A7bRemlKn6utU7XtnilKpO /sfhL91OLUUPchdaXkS7zeeqKclNtfcLahOJgUir3S2/MkW1h23saBw2D+HYG83eFy k3R+SKNPzKJFgt+cNH2aeuwGROJiAe37hBNKdtD/Mlmei/raN9KEOUv+tQQo3dcDpC ufadyE/JK5jmg== Received: by mercury (Postfix, from userid 1000) id 61E1310608B3; Thu, 9 Mar 2023 23:50:43 +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: [PATCHv1 02/11] power: supply: core: auto-exposure of simple-battery data Date: Thu, 9 Mar 2023 23:50:32 +0100 Message-Id: <20230309225041.477440-3-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309225041.477440-1-sre@kernel.org> References: <20230309225041.477440-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: Linus Walleij Reviewed-by: Matti Vaittinen --- drivers/power/supply/power_supply_core.c | 153 +++++++++++++++++++--- drivers/power/supply/power_supply_sysfs.c | 16 +++ include/linux/power_supply.h | 31 +++++ 3 files changed, 181 insertions(+), 19 deletions(-) diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index f3d7c1da299f..c3684ec46b3f 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,111 @@ void power_supply_put_battery_info(struct power_supply *psy, } EXPORT_SYMBOL_GPL(power_supply_put_battery_info); +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 +1151,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,9 +1177,13 @@ 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(psy->desc->expose_battery_info) + return power_supply_battery_info_get_prop(psy->battery_info, psp, val); + else + return -EINVAL; } -EXPORT_SYMBOL_GPL(power_supply_get_property); int power_supply_set_property(struct power_supply *psy, enum power_supply_property psp, @@ -1117,22 +1242,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 +1364,12 @@ __power_supply_register(struct device *parent, goto check_supplies_failed; } + if (psy->desc->expose_battery_info) { + rc = power_supply_get_battery_info(psy, &psy->battery_info); + if (rc) + 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..8822a17f9589 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -380,6 +380,11 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj, } } + if (psy->desc->expose_battery_info) { + if (power_supply_battery_info_has_prop(psy->battery_info, attrno)) + return mode; + } + return 0; } @@ -488,6 +493,17 @@ int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env) goto out; } + if (psy->desc->expose_battery_info) { + for (j = 0; j < ARRAY_SIZE(power_supply_battery_info_properties); j++) { + if (!power_supply_battery_info_has_prop(psy->battery_info, power_supply_battery_info_properties[j])) + continue; + ret = add_prop_uevent(dev, env, power_supply_battery_info_properties[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..de0ea8320f3d 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -275,6 +275,13 @@ struct power_supply_desc { * sensors or other supplies. */ bool no_thermal; + /* + * Set if constant battery information from firmware should be + * exposed automatically. No driver specific code is required + * in that case. If the driver also handles a property provided + * by constant firmware data, the driver's handler is preferred. + */ + bool expose_battery_info; /* For APM emulation, think legacy userspace. */ int use_for_apm; }; @@ -301,6 +308,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; @@ -766,6 +774,24 @@ struct power_supply_battery_info { int bti_resistance_tolerance; }; +static 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, +}; + extern struct atomic_notifier_head power_supply_notifier; extern int power_supply_reg_notifier(struct notifier_block *nb); extern void power_supply_unreg_notifier(struct notifier_block *nb); @@ -795,6 +821,11 @@ 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 Thu Mar 9 22:50: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: 13168511 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 1D29FC74A44 for ; Thu, 9 Mar 2023 22:50:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230256AbjCIWuz (ORCPT ); Thu, 9 Mar 2023 17:50:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229983AbjCIWux (ORCPT ); Thu, 9 Mar 2023 17:50:53 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31C01F4B6C; Thu, 9 Mar 2023 14:50:47 -0800 (PST) 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 C4F8161D13; Thu, 9 Mar 2023 22:50:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02A2CC4339C; Thu, 9 Mar 2023 22:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678402246; bh=a3VYe+fYM8Slw651PTtj6eTDFBaG7Vg0KmpeutoQk4s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r2+vqizYR3y4nyC33J1olLG191fKPuABLSbgzE/Wh6fi9yqP/EVbG2AJfTTQh8Zsq /IzyRgHiwvkw37k6IPhvY/mveLaP5Ga8RHGbR4354R4vpQfqxW5Kd8mzk4EdH4oTT5 ylplyifqXrqMg7E3CkLvSQVzUkgqGF9eG+F6R6kWcCeGE6gl+2qAmMVIz1Qa5OydzF /OXcFCHoPtL9laMK9xRzq8KmzjJXEM92awTSsspUgqTeToiJkW8yd6g/VsXA50KmsI jyTEZcQgtlNXHlh+0almiuzPj+bd07cmarHyT6I+hnGauXmWJcExl/nEXIkNLERa6Z OF+lF88AxckIA== Received: by mercury (Postfix, from userid 1000) id 628041060998; Thu, 9 Mar 2023 23:50:43 +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: [PATCHv1 03/11] power: supply: generic-adc-battery: convert to managed resources Date: Thu, 9 Mar 2023 23:50:33 +0100 Message-Id: <20230309225041.477440-4-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309225041.477440-1-sre@kernel.org> References: <20230309225041.477440-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. Signed-off-by: Sebastian Reichel Reviewed-by: Linus Walleij Reviewed-by: Matti Vaittinen --- 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 Thu Mar 9 22:50:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13168509 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 0235DC6FD1C for ; Thu, 9 Mar 2023 22:50:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229506AbjCIWux (ORCPT ); Thu, 9 Mar 2023 17:50:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230509AbjCIWuw (ORCPT ); Thu, 9 Mar 2023 17:50:52 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31741F209C; Thu, 9 Mar 2023 14:50:47 -0800 (PST) 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 C294C61D12; Thu, 9 Mar 2023 22:50:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2380C433EF; Thu, 9 Mar 2023 22:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678402246; bh=YniPoXTs7rUu0i27ecAmQDdt91YnlzI00Xc0ywnf1UY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wx0vjHLpV930/MkCtPtQ2SgZ7mFaMJppT5NIg6aH0RuEd/E2/6rmJi2gRAft8DmGo 52cTBqBf6v3q90PuhM5u07rX0hebzZVuv0Xr6v+MLAcPDyGVN475y0sOkbMXih1Q/e H4JUTiCXgum/1E8cYKIP/DN0roctGIy5eY33yjdEfi+nqTzJPrM3V3C+3BBOcv4SE2 bGagRoMkMru3aIP97E1f0Rf6E7l6QMe8lqtaRy0RgdYZgDQXEpFxaiubJ6UolFU3WK NTnFnlerv6tknt2kdfdqclW81rsiyuqOYOI/QXzAXeREtgDn8yh8g0ojei3LKRJ99/ j+jBXWJTjm8pQ== Received: by mercury (Postfix, from userid 1000) id 631D710609CD; Thu, 9 Mar 2023 23:50:43 +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: [PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling Date: Thu, 9 Mar 2023 23:50:34 +0100 Message-Id: <20230309225041.477440-5-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309225041.477440-1-sre@kernel.org> References: <20230309225041.477440-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. Signed-off-by: Sebastian Reichel Reviewed-by: Linus Walleij Reviewed-by: Matti Vaittinen --- 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 Thu Mar 9 22:50: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: 13168516 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 D3AC4C64EC4 for ; Thu, 9 Mar 2023 22:51:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231264AbjCIWvN (ORCPT ); Thu, 9 Mar 2023 17:51:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231435AbjCIWu6 (ORCPT ); Thu, 9 Mar 2023 17:50:58 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D985F73AD; Thu, 9 Mar 2023 14:50:51 -0800 (PST) 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 0D494B820E1; Thu, 9 Mar 2023 22:50:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80958C4339E; Thu, 9 Mar 2023 22:50:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678402248; bh=wvOJ8rQ6bnzbunmB5UwoBejQRHk8rSnA78s83MjDCC0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=icDVNSzDQyZrsEydVf10tIyhdVrFrl3j0Su/1/DUBMa0hMowj9yF5Yyv6qTR0jMXZ i/UvAs1Z6/WbEzRDUYzK0/GpgCBxHuXomhebAh8x8ZzqG05q1YUXza8++cGfa6wWNv bCbHCHL+8RQKz014Q9DuSLWPFuMO0I4DUOFiljk1hAK8hWutDjyW2lA7FajmGXBOUJ B6uru2D+9duOoW20Wme02IkMoGA8FSzn+2kajPq1lpHF5jx9Lv4U/HMK6mk+rfhbp1 nkHCwwoSlbY/2J2AHRc1Jg6CXJMDCo7syePatDMxeV4wPbyBgYO98shQYZdC8eVTZm t5VzOJ9DuXq0w== Received: by mercury (Postfix, from userid 1000) id 6399B10609DA; Thu, 9 Mar 2023 23:50:43 +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: [PATCHv1 05/11] power: supply: generic-adc-battery: drop jitter delay support Date: Thu, 9 Mar 2023 23:50:35 +0100 Message-Id: <20230309225041.477440-6-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309225041.477440-1-sre@kernel.org> References: <20230309225041.477440-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. Signed-off-by: Sebastian Reichel Reviewed-by: Linus Walleij --- 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 Thu Mar 9 22:50:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13168515 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 974C7C6FD1C for ; Thu, 9 Mar 2023 22:51:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231432AbjCIWvB (ORCPT ); Thu, 9 Mar 2023 17:51:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231421AbjCIWu6 (ORCPT ); Thu, 9 Mar 2023 17:50:58 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A166F6C77; Thu, 9 Mar 2023 14:50:51 -0800 (PST) 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 DE38DB82126; Thu, 9 Mar 2023 22:50:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FDB8C433D2; Thu, 9 Mar 2023 22:50:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678402248; bh=VYhOuoj42MSKuPzveR1C3Vzmh0B87Z6hDNN0FMDUz74=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ucfeeQqPLZumezdSghzWNrUjjSoAAZF5VcHqdt8g76AiQpbiPNA4POsIMgoefstfe jt57JVa8G3qQz/eIByDSazevLjqsdXaCx7pdsJtv7ezYgMiQClq1zpYI8Kz1eCeeoF tfFeiH70xcyaLyrpoH2Ss1dBF42zD3Yl2SCdAN6BdxDMlyKnuxURUyePPEyQ4lsUlh 5Icekw7R414kyFM7PeQqeXChlscIk2QxprgKHXZpTX8SIqYAuXj3D4uGzC+p63G7O4 rjghZ1ydcBXBWM+whEpfE8E8z/Yr9W8AyLQ22LcbyqPinUnHcsaoA2ywPvGFP8yfGV XuC2TAOpQD0AQ== Received: by mercury (Postfix, from userid 1000) id 6412710609DB; Thu, 9 Mar 2023 23:50:43 +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: [PATCHv1 06/11] power: supply: generic-adc-battery: drop charge now support Date: Thu, 9 Mar 2023 23:50:36 +0100 Message-Id: <20230309225041.477440-7-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309225041.477440-1-sre@kernel.org> References: <20230309225041.477440-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. Signed-off-by: Sebastian Reichel Reviewed-by: Linus Walleij Reviewed-by: Matti Vaittinen --- 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 Thu Mar 9 22:50:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13168519 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 C5657C74A44 for ; Thu, 9 Mar 2023 22:51:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231557AbjCIWvV (ORCPT ); Thu, 9 Mar 2023 17:51:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231446AbjCIWvA (ORCPT ); Thu, 9 Mar 2023 17:51:00 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35C2DE6804; Thu, 9 Mar 2023 14:50:53 -0800 (PST) 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 3EC1E61D1E; Thu, 9 Mar 2023 22:50:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75B4AC4339B; Thu, 9 Mar 2023 22:50:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678402248; bh=pgooTjpmkH0T4+938WzlRJ0u+gHeFjR0k59+b8+puVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GsH0euTea8XbVDNJPjcjtoGVLcP+H6/i0ezskqym3D/VJOpYF99vba96il72ceyE7 Z8f/89TntYNQpJtZfJT1QiQjQRLeJHJfCjC5vuHPK5DI2mBEFnvzMy/+llBBGuD0TJ qV74i74QGJpEgi31xRKY6+92kkCmrMf6onKOQZ9D44wzaA2ApmBCzzCzybXjVNCu4V XVGqKiRhM/0IH+7PbRqCoAQRLS5oNR9ZuFsCtP/WGSp8A+NOssZJzbmm6DSwl/2XPc pP/00G06EIo7gmR9lQjkg7k6U8LO8BURT91RDEKknFhDK3WEAxZXlrr5JtzHQXtL5K VA3ihawG6VHqQ== Received: by mercury (Postfix, from userid 1000) id 6536310609DE; Thu, 9 Mar 2023 23:50:43 +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: [PATCHv1 07/11] power: supply: generic-adc-battery: drop memory alloc error message Date: Thu, 9 Mar 2023 23:50:37 +0100 Message-Id: <20230309225041.477440-8-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309225041.477440-1-sre@kernel.org> References: <20230309225041.477440-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. Signed-off-by: Sebastian Reichel Reviewed-by: Linus Walleij Reviewed-by: Matti Vaittinen --- 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 Thu Mar 9 22:50:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13168514 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 9E511C7618B for ; Thu, 9 Mar 2023 22:51:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231436AbjCIWu7 (ORCPT ); Thu, 9 Mar 2023 17:50:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231400AbjCIWuz (ORCPT ); Thu, 9 Mar 2023 17:50:55 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA1A1F9EDD; Thu, 9 Mar 2023 14:50:49 -0800 (PST) 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 366FC61D26; Thu, 9 Mar 2023 22:50:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6ADE2C433EF; Thu, 9 Mar 2023 22:50:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678402248; bh=/6k04eEl52blbA5RWXlAMS3FZFJp/si00AtoB5jWUi0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eoBnYatnn5omFjQzLW9OGHv8JuoYUBtbp/nksrFQM4h/ClufLKJcrRvbBFqOcnOP8 22fgDOC6LVSyyihld9PCVelLNjaZoIA8eTO8z9+2nGovJFZeOjc6AYMtd1HEs66GdH COUruQqMVqCsIJAN/azo8ssJia6QfTY7BYaWBq58gajB6gEevzCt7CLJhuJSDDo+fP YuiWc3f6uhJ4Nw+HU358IfqsM/cNzYQqR1gsv0splCHYqXNuf/d9EziGEY/iH14Wt7 kx0sBzftwmPwdgn4DvN6sz+jd7J0lgAmNPW1cQelZk/d9gsMcInxe95jeIeFRSmQbP n6bNyT9WVwHsQ== Received: by mercury (Postfix, from userid 1000) id 678F71060FAB; Thu, 9 Mar 2023 23:50:43 +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: [PATCHv1 08/11] power: supply: generic-adc-battery: use simple-battery API Date: Thu, 9 Mar 2023 23:50:38 +0100 Message-Id: <20230309225041.477440-9-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309225041.477440-1-sre@kernel.org> References: <20230309225041.477440-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. Signed-off-by: Sebastian Reichel Reviewed-by: Linus Walleij --- drivers/power/supply/generic-adc-battery.c | 65 ++-------------------- include/linux/power/generic-adc-battery.h | 18 ------ 2 files changed, 5 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..fc6fcfda1ef2 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 @@ -309,6 +253,7 @@ static int gab_probe(struct platform_device *pdev) */ psy_desc->properties = properties; psy_desc->num_properties = index; + psy_desc->expose_battery_info = true; adc_bat->psy = devm_power_supply_register(&pdev->dev, psy_desc, &psy_cfg); if (IS_ERR(adc_bat->psy)) 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 Thu Mar 9 22:50:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13168517 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 57B34C6FD1C for ; Thu, 9 Mar 2023 22:51:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231501AbjCIWvT (ORCPT ); Thu, 9 Mar 2023 17:51:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231443AbjCIWvA (ORCPT ); Thu, 9 Mar 2023 17:51:00 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35123E4D8B; Thu, 9 Mar 2023 14:50:53 -0800 (PST) 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 59F8561D1D; Thu, 9 Mar 2023 22:50:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BF22C433A1; Thu, 9 Mar 2023 22:50:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678402248; bh=VNPfceYdTa2oGjCGoB+LsPxhV3yGArTJZyG+RrFRufQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pww8Y39uuXBt+nherJ04UzfjKkKoVoX1ftmIk/DTOku89PYtHhehnztGiUaJdFiue mN9XUYw/YmbE+2LPTh8IKLn5FMLiXuGL8zLMAJHIykb7D5Hlpj8xhwv3X56mYURFLz DEXSBlIEKZEWFsVB+fBLj9FVdGwMRPsznvcIuZksLt5qMFcByLqeZssDV+y36Gg6Mq sngvaV2MTRjzORzTOY3Uc/K70TnkrVBC5JQy4gc+6Dq/VW1OOnHcE0ceZtrigeOy1J dEFgLsYPpVtT0TSnxgKYJqDRGGEUDWhel8aicUaZ7eshHJzgdFFh5fHXoHki/y7Tid E6sw2GCm5gFhw== Received: by mercury (Postfix, from userid 1000) id 69F821060FD4; Thu, 9 Mar 2023 23:50:43 +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: [PATCHv1 09/11] power: supply: generic-adc-battery: simplify read_channel logic Date: Thu, 9 Mar 2023 23:50:39 +0100 Message-Id: <20230309225041.477440-10-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309225041.477440-1-sre@kernel.org> References: <20230309225041.477440-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(). Signed-off-by: Sebastian Reichel Reviewed-by: Linus Walleij Reviewed-by: Matti Vaittinen --- 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 fc6fcfda1ef2..7bc54566664f 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 Thu Mar 9 22:50:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13168520 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 A73A7C7618A for ; Thu, 9 Mar 2023 22:51:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231591AbjCIWvW (ORCPT ); Thu, 9 Mar 2023 17:51:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231315AbjCIWvA (ORCPT ); Thu, 9 Mar 2023 17:51:00 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBEBFE4C5E; Thu, 9 Mar 2023 14:50:53 -0800 (PST) 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 C3A476144D; Thu, 9 Mar 2023 22:50:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6891C4339C; Thu, 9 Mar 2023 22:50:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678402248; bh=z3LXcJW+sEBhmEZPY8ualsCbQ2lqWkL1B6hI4RYGoAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B/huSY6Tk3xFD3nSML276xY1+bAdQsv1uAJXa4YOLzLXQrq6LLzMdzLyu8+L1+6mI rSt2/P3uwGrYYQEhM2XN8XviPow5lY3kopYU0EIT7RXINO8c6rXHY54IjVQsSOam4y W/kCYw1DJtvdYvB0euDGSc31kRBmh7ZxGILjL6pkd/6zZS2YVDVvKEHu/geofzWHFt TSDJhqYUnihK7KzVRCshCTGR5zDeDH9pUigE4lJW2W6LM29i6VoyV4EPhF9KI7YQHI p75OBuTDkgi2hVY2WaAfepOsM+WI48QgOO+98qMc0Jc7sJOUcreJBL31/GiINr55gO Gb0Da6njfhlUQ== Received: by mercury (Postfix, from userid 1000) id 6C08D1061BBD; Thu, 9 Mar 2023 23:50:43 +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: [PATCHv1 10/11] power: supply: generic-adc-battery: add DT support Date: Thu, 9 Mar 2023 23:50:40 +0100 Message-Id: <20230309225041.477440-11-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309225041.477440-1-sre@kernel.org> References: <20230309225041.477440-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. Signed-off-by: Sebastian Reichel Reviewed-by: Linus Walleij Reviewed-by: Matti Vaittinen --- 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 7bc54566664f..436e75d226ed 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 */ @@ -170,6 +171,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); @@ -284,10 +286,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 Thu Mar 9 22:50:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 13168518 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 84063C6FD1F for ; Thu, 9 Mar 2023 22:51:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231537AbjCIWvU (ORCPT ); Thu, 9 Mar 2023 17:51:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231445AbjCIWvA (ORCPT ); Thu, 9 Mar 2023 17:51:00 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB9993C791; Thu, 9 Mar 2023 14:50:53 -0800 (PST) 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 C824C61D20; Thu, 9 Mar 2023 22:50:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8FFDC433A7; Thu, 9 Mar 2023 22:50:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678402248; bh=B2rIHqE7234kAZRPUOTS1Nsn1bhxYVZgs/rCANZZIM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K/POFntf5lpb9LQj2VkYsSIlG8RQ3Q/A+qI5ewAi6EX3N1+cz5v5PSseS20Hef/6b k3vhzADdubr1dVbWfpsp+HRZTpuHY5uVtHPIq++0J3FN/jA3X0aOyjmPaoIe2EhLj2 vDlO8Mmgo86jiUgDa/5Sw4JZH5Ks91rZrRI6c8/d02Z8jeVanxTWoll8d/QQE//rl+ Kyn7+epqDLDNsYCmyTxnBowOpSxTqeuKne/RR7JmjNO6k66oshlh8D2nUcadV121cB Lnn+JToPmWnzZhF67rDlXpg5xc3+lBmYe2LCBTSPQ8Unq29Jk5bZ3BQw0q/mLmg0LK DVsIncTovlZyw== Received: by mercury (Postfix, from userid 1000) id 6DFA51061BBE; Thu, 9 Mar 2023 23:50:43 +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: [PATCHv1 11/11] power: supply: generic-adc-battery: update copyright info Date: Thu, 9 Mar 2023 23:50:41 +0100 Message-Id: <20230309225041.477440-12-sre@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230309225041.477440-1-sre@kernel.org> References: <20230309225041.477440-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. Signed-off-by: Sebastian Reichel Reviewed-by: Linus Walleij Reviewed-by: Matti Vaittinen --- 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 436e75d226ed..ac72140dc136 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