Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3737873pxv; Mon, 5 Jul 2021 04:38:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeRE7ZBsU7aWx+Dfc1AvVQzt4rud7Gdbrme+cx3vEzTuViT880gb1rlvqslyAg3M0rTgdt X-Received: by 2002:a05:6402:198:: with SMTP id r24mr15844027edv.93.1625485124351; Mon, 05 Jul 2021 04:38:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625485124; cv=none; d=google.com; s=arc-20160816; b=v6WVeosmooB0hC5L3zCiC5M9j4fAr56fq1OJu5+1QlQwu0oPUB6IVZAEbw7PJ4U2O+ JunORk+IoXPe+WrmoE5fgBMN000QCrcxPrt/7acVohpAr70sWqEuhUORflhhGb0YZHF9 81+Q//S+4awflKPN6VbVA88tIOVeo4Z4syGXW6W5zsdmqIA4G9KL0msVsmtrlma1bRBy 1OH14kTQKmzVrwl7rODzR/j1VCDwIQz/U8lyWclZWPNuwG7HeTmPwuG6+mkIuH2SRkeY M2Glj/UinUf4x0MruHNElqmg/WkkpkXPlBs3vkb6hInGeMlJZD/FjcEf6l0/Qg35leNa vC7w== 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=hBQwvrRZMyyx+hqSIGn7N5kouJhnwb/IRRG3Wnr0q7U=; b=N6Jo19IyuWm8xTp3TAAXfXABPAXApstI9L1vVnF5xJw9GkRSDe93cSrYonMYGbHVLm TwkzRHrT9ZpDbF8kIPw+WK1zBj+2jZm2YtFh956ZbKTdgH94LrbOrwE9zITvuqO7vwWr VxeF8pAV2iySQDV7RXNNmnQAHFeMs0FXSzrIonvDYohstZ9Si/ERskvtPEEC1gqI8QKW ME8VK27DD5/1G0o28PlM20vLqbNKtOw3XAXluD1bw4UGV5H9po5azVMlK9ig7toXtjU0 q+9iPK5d/2x5KO/Wiqi2U771pV9om0yNAB2blzMXNdxuxY8ABB1vdCRaHUceZ7DibDGQ wX2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b=d7gjOkIr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jg37si11087022ejc.738.2021.07.05.04.38.20; Mon, 05 Jul 2021 04:38:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b=d7gjOkIr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231332AbhGELji (ORCPT + 99 others); Mon, 5 Jul 2021 07:39:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231279AbhGELjf (ORCPT ); Mon, 5 Jul 2021 07:39:35 -0400 Received: from mail.andi.de1.cc (mail.andi.de1.cc [IPv6:2a01:238:4321:8900:456f:ecd6:43e:202c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96AB3C061574; Mon, 5 Jul 2021 04:36:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kemnade.info; s=20180802; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=hBQwvrRZMyyx+hqSIGn7N5kouJhnwb/IRRG3Wnr0q7U=; b=d7gjOkIrTI1LRRGHNSJuK7RFq+ f77lSBRyfJ6FqYttw7uDgx0ZlQWxj+lD/Gw7VqFUfaN+6kQICUkcODzTXlgTWDdtmlwU54PqFXupF 0ibqeVoSkdep5Sgq2hRCTg8iJK2VTk2m4QbTZ4rOaoraOa5nA7Z2mJR7vn9aIGUewpKs=; Received: from p200300ccff0e44001a3da2fffebfd33a.dip0.t-ipconnect.de ([2003:cc:ff0e:4400:1a3d:a2ff:febf:d33a] helo=aktux) by mail.andi.de1.cc with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1m0MuE-0007D4-S9; Mon, 05 Jul 2021 13:36:55 +0200 Received: from andi by aktux with local (Exim 4.92) (envelope-from ) id 1m0MuE-0007XT-KK; Mon, 05 Jul 2021 13:36:54 +0200 From: Andreas Kemnade To: jic23@kernel.org, lars@metafoo.de, sre@kernel.org, andreas@kemnade.info, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, letux-kernel@openphoenux.org Cc: kernel test robot Subject: [PATCH v2 2/2] power: supply: rn5t618: Add voltage_now property Date: Mon, 5 Jul 2021 13:36:37 +0200 Message-Id: <20210705113637.28908-3-andreas@kemnade.info> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210705113637.28908-1-andreas@kemnade.info> References: <20210705113637.28908-1-andreas@kemnade.info> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -1.0 (-) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Read voltage_now via IIO and provide the property. Signed-off-by: Andreas Kemnade Reported-by: kernel test robot --- Changes in v2: - different error handling needed for iio_map usage - fix dependencies in Kconfig drivers/power/supply/Kconfig | 2 ++ drivers/power/supply/rn5t618_power.c | 40 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index e696364126f1..b2910d950929 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -790,6 +790,8 @@ config CHARGER_WILCO config RN5T618_POWER tristate "RN5T618 charger/fuel gauge support" depends on MFD_RN5T618 + depends on RN5T618_ADC + depends on IIO help Say Y here to have support for RN5T618 PMIC family fuel gauge and charger. This driver can also be built as a module. If so, the module will be diff --git a/drivers/power/supply/rn5t618_power.c b/drivers/power/supply/rn5t618_power.c index 819061918b2a..bca3fd86c14d 100644 --- a/drivers/power/supply/rn5t618_power.c +++ b/drivers/power/supply/rn5t618_power.c @@ -9,10 +9,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -64,6 +66,8 @@ struct rn5t618_power_info { struct power_supply *battery; struct power_supply *usb; struct power_supply *adp; + struct iio_channel *channel_vusb; + struct iio_channel *channel_vadp; int irq; }; @@ -77,6 +81,7 @@ static enum power_supply_usb_type rn5t618_usb_types[] = { static enum power_supply_property rn5t618_usb_props[] = { /* input current limit is not very accurate */ POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, + POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_USB_TYPE, POWER_SUPPLY_PROP_ONLINE, @@ -85,6 +90,7 @@ static enum power_supply_property rn5t618_usb_props[] = { static enum power_supply_property rn5t618_adp_props[] = { /* input current limit is not very accurate */ POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, + POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_ONLINE, }; @@ -464,6 +470,16 @@ static int rn5t618_adp_get_property(struct power_supply *psy, val->intval = FROM_CUR_REG(regval); break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + if (!info->channel_vadp) + return -ENODATA; + + ret = iio_read_channel_processed(info->channel_vadp, &val->intval); + if (ret < 0) + return ret; + + val->intval *= 1000; + break; default: return -EINVAL; } @@ -589,6 +605,16 @@ static int rn5t618_usb_get_property(struct power_supply *psy, val->intval = FROM_CUR_REG(regval); } break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + if (!info->channel_vusb) + return -ENODATA; + + ret = iio_read_channel_processed(info->channel_vusb, &val->intval); + if (ret < 0) + return ret; + + val->intval *= 1000; + break; default: return -EINVAL; } @@ -711,6 +737,20 @@ static int rn5t618_power_probe(struct platform_device *pdev) platform_set_drvdata(pdev, info); + info->channel_vusb = devm_iio_channel_get(&pdev->dev, "vusb"); + if (IS_ERR(info->channel_vusb)) { + if (PTR_ERR(info->channel_vusb) == -ENODEV) + return -EPROBE_DEFER; + return PTR_ERR(info->channel_vusb); + } + + info->channel_vadp = devm_iio_channel_get(&pdev->dev, "vadp"); + if (IS_ERR(info->channel_vadp)) { + if (PTR_ERR(info->channel_vadp) == -ENODEV) + return -EPROBE_DEFER; + return PTR_ERR(info->channel_vadp); + } + ret = regmap_read(info->rn5t618->regmap, RN5T618_CONTROL, &v); if (ret) return ret; -- 2.30.2