Message ID | 20230314225535.1321736-11-sre@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2029026wrd; Tue, 14 Mar 2023 16:06:05 -0700 (PDT) X-Google-Smtp-Source: AK7set8IiT7sslyUysrw9QKK2ZyNyciFf0CGbNzZ68jPNI1g8ppoFIKSyoD0P9CKlc4yXDCkxHt+ X-Received: by 2002:a62:3001:0:b0:5d2:1d72:3b31 with SMTP id w1-20020a623001000000b005d21d723b31mr34882663pfw.2.1678835165611; Tue, 14 Mar 2023 16:06:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678835165; cv=none; d=google.com; s=arc-20160816; b=pLZ1H0vgyNVdfHHhE6tinLZtfWGfry/fXOx9TjiBY3xj1EkbquntFokP9NImEc8wPa C6ItA5rIc1SoD7vPSz/J7MgPZ2gtirSsgsBJ9us8BOef+WX5T5idQnuPaB6EzGhuKpaF O1hda59+A6kt9fVIG9DHqCRCBN7tS96Uy5am5oGuSKBCJE6Pf7r4myfJxU3NFfzEzWEe gaBoV/TUeysFz5WQ4v8swpy7fex5XLZXcLcIqw2M/PzWF94wd5VheFKAJJn7B2Y6RWjq UUFHwzWrmpSHdzBn5ZfKY2lhKso9vQCO8dsPfT+t5sctidEK6uY6YTxQs6XdXsmnxGZ+ RTEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=13+1KqBd/Uc1XF2yAgo1OWNVJErAZvRMWtK3qq5I3VA=; b=t/b3D7LK1GXR9IBFiagEj3pEmw3jx6t0Digj7mgI1tDdgBIR+vGsyEQDzIiJpbeQwa dGNhG8vGgrnJYBNZr+q7SYhDn/jOulVqAMD3G9V3c+OK/dC8oU6R8MHzglmFndcAQLJk 4kZSkbeY3M7xNPOYl9SyrcmXpWB7MzyAcvWMGovtp7t9UnuE4mX2WnFQoxN6KmyYgfYK vXJMTXHBt73drgvl7lGrr09/5T8heAQ7R2HGGn8vr1J6hagZxPaN+Ypp1JD4xIFq21QZ O1fK8J2doqfPnv2J6HnHbI/p5VInxir90pVz9atKvYAVD/+dFasXbNLTVasVjA+r2eX9 5GRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WHHYd5al; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g17-20020a63dd51000000b00508eeafc9ecsi3199556pgj.176.2023.03.14.16.05.39; Tue, 14 Mar 2023 16:06:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WHHYd5al; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230111AbjCNW4O (ORCPT <rfc822;realc9580@gmail.com> + 99 others); Tue, 14 Mar 2023 18:56:14 -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 <rfc822;linux-kernel@vger.kernel.org>); 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 <sre@kernel.org> To: Sebastian Reichel <sre@kernel.org> Cc: Linus Walleij <linus.walleij@linaro.org>, Matti Vaittinen <mazziesaccount@gmail.com>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, Sebastian Reichel <sebastian.reichel@collabora.com> 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760386262692706541?= X-GMAIL-MSGID: =?utf-8?q?1760386262692706541?= |
Series |
Add DT support for generic ADC battery
|
|
Commit Message
Sebastian Reichel
March 14, 2023, 10:55 p.m. UTC
From: Sebastian Reichel <sebastian.reichel@collabora.com> Another typical thing to monitor via an ADC line is the battery temperature. Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> --- drivers/power/supply/generic-adc-battery.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Comments
On 3/15/23 00:55, Sebastian Reichel wrote: > From: Sebastian Reichel <sebastian.reichel@collabora.com> > > Another typical thing to monitor via an ADC line is > the battery temperature. > > Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com> > --- > 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; > }
On Tue, Mar 14, 2023 at 11:55 PM Sebastian Reichel <sre@kernel.org> wrote: > From: Sebastian Reichel <sebastian.reichel@collabora.com> > > Another typical thing to monitor via an ADC line is > the battery temperature. > > Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> > 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); Hm. I wonder if these should rather all use read_channel_processed()? The difference is that you will then support ADCs with internal scaling which is beneficial. Most of the time it doesn't matter. Yours, Linus Walleij
Hi Linus, On Wed, Mar 15, 2023 at 09:04:15AM +0100, Linus Walleij wrote: > On Tue, Mar 14, 2023 at 11:55 PM Sebastian Reichel <sre@kernel.org> wrote: > > From: Sebastian Reichel <sebastian.reichel@collabora.com> > > Another typical thing to monitor via an ADC line is > > the battery temperature. > > > > Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> > > Reviewed-by: Linus Walleij <linus.walleij@linaro.org> > > > 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); > > Hm. I wonder if these should rather all use read_channel_processed()? > > The difference is that you will then support ADCs with internal scaling > which is beneficial. Most of the time it doesn't matter. read_channel is a local helper, the driver uses the processed variant of iio_read_channel: static int read_channel(struct gab *adc_bat, enum gab_chan_type channel, int *result) { int ret; ret = iio_read_channel_processed(adc_bat->channel[channel], result); if (ret < 0) pr_err("read channel error\n"); else *result *= 1000; return ret; } -- Sebastian
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; }