From patchwork Wed Aug 21 21:54:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13772162 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E0388C52D7C for ; Wed, 21 Aug 2024 21:59:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=WkTLpaLrmy3BxDBwaB1+2Zmk+X/0Igy34RCtn19SnOY=; b=AxDP6bU4J2vN5f5CsPBUz7Dldc ltKe9QhE9RetH9vwqLKnT7F08fWykysYd+2mx4vX8Fx+pRldT6wJxWW3ELV/3YqaJgeH7enYEzWhE qBmssovJroVrpzh72FcoPsUw/gG3+8w3lgousc16BEiV0MDP4dSYY4iGP4jPxo+5QllrRZG2CjlXQ T34blzNbGjyL6MnIk3oUe8OkQMMO+/YHL3TqElbPextQaILAm3IVSYRC6XKmxFY35Im+Irrfifcl4 8C3T2RuRkuIfSEyjiuL5f4f1T6yLU+AVVi+gEEtBOY7nSfXY3ZfvtzX3cmobZw4M4V3DSDB5wG+nb EzOmM97Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtM3-0000000AUPh-3pz7; Wed, 21 Aug 2024 21:59:00 +0000 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtKc-0000000AU32-2w02 for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 21:57:33 +0000 Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3db18c4927bso100139b6e.1 for ; Wed, 21 Aug 2024 14:57:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724277449; x=1724882249; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WkTLpaLrmy3BxDBwaB1+2Zmk+X/0Igy34RCtn19SnOY=; b=NX+4XVmh8oT4FKvKg4JEjEQBZDESWF4NYr83izZLjkwWxVXDcb2teO//4809pfwgCz kWKGwM0N4tcsisDCCqGizyjGVVTbjc6KEgfDsbhEQU9LCXLrLDvoSglxBytN5efIFOhd vgtbd2bSELnx/2ABG9+r6XvUYL6oDpQAjavz9R/Fo796sGKSuVB5AtQwoKoXUAvDyG9A h0Ukb3b/LbuUNnK4cv0zeNKCpKRdqYoLHOdYdSTNA5q9Lq75ehaESqbOjPzF3FWB2jct 2+AWEsJoR/KN8pCUsN8RE33VH9EQZc84W1oL+q34kTNSaB4r6dkdd3JPu43OK/xU0ofh Zylg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724277449; x=1724882249; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WkTLpaLrmy3BxDBwaB1+2Zmk+X/0Igy34RCtn19SnOY=; b=JilWs+ZmqzmYQsP1wQqTZyyWeNuHOsni9fs7DBav+5OlOUvx4FJUpzLWr+tyXG8k+8 wG+gehcQ7fIldcPHw0OLwJqqC8bgc7IMf+4ncsJ3KoFccc/i2Ms3cepvgnbl7F0ZPkZ2 hMfNJAOC17psOvo7bKDGUCnx3bj0xTvMgnCbIGQ++F2P2BDPYc10KLpw7PqVlpmxft+B iHLABHTC9H7uiCGuUKiSMrs+80M4Dlu76upWi486lw8uKgPyF2PJDh+rwUvIX4z4+Gac nqbD4zEM4lulEWfEvrgE6VqJ7JkPpD9fu1C/Q4vlnJeuYJpYKvjWrtUXxsL7J0CgQBAE JdwA== X-Forwarded-Encrypted: i=1; AJvYcCXoaricGUHsWISYjitaOk3imUTU4EJHOy2aJEynFaioO/qTbFCZ8fa8ZdQZFy0N7MdaSHeSnkHbrTzYvE2TK18U@lists.infradead.org X-Gm-Message-State: AOJu0Yxs/CNXQKyivrckLUdx4+LxcXntepw5Fqtu2z6CoP7BxQvPL4Ow 1vRMCZlk/P+/lbTmMPugUauc1CWDW2kJuHDUr/zI4X3Bb++ZftdY X-Google-Smtp-Source: AGHT+IG0g+ItvbLGFC4CrC1tDA+EwYrPd6P5p9u4y4eTdOg8SYQpZesNcarolPBA3iTnoSWiVjSeXQ== X-Received: by 2002:a05:6808:3090:b0:3dd:4376:db2c with SMTP id 5614622812f47-3de194e0b70mr5175137b6e.9.1724277449522; Wed, 21 Aug 2024 14:57:29 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf:81a9:2325:e0f7:7376]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225555b6sm47070b6e.17.2024.08.21.14.57.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 14:57:29 -0700 (PDT) From: Chris Morgan To: linux-sunxi@lists.linux.dev Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com, mripard@kernel.org, tgamblin@baylibre.com, aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de, lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, jic23@kernel.org, jonathan.cameron@huawei.com, Chris Morgan , Jonathan Cameron Subject: [PATCH V4 01/15] iio: adc: axp20x_adc: Add adc_en1 and adc_en2 to axp_data Date: Wed, 21 Aug 2024 16:54:42 -0500 Message-Id: <20240821215456.962564-2-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821215456.962564-1-macroalpha82@gmail.com> References: <20240821215456.962564-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_145730_774072_3AF79696 X-CRM114-Status: GOOD ( 17.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chris Morgan Add the register for adc_en1 and adc_en2 to the axp_data struct. This allows us to specify a different register to enable the adc channels for different devices such as the AXP717. Acked-by: Jonathan Cameron Signed-off-by: Chris Morgan --- drivers/iio/adc/axp20x_adc.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/axp20x_adc.c b/drivers/iio/adc/axp20x_adc.c index b487e577befb..368ba6ee7a80 100644 --- a/drivers/iio/adc/axp20x_adc.c +++ b/drivers/iio/adc/axp20x_adc.c @@ -889,7 +889,9 @@ struct axp_data { const struct iio_info *iio_info; int num_channels; struct iio_chan_spec const *channels; + unsigned long adc_en1; unsigned long adc_en1_mask; + unsigned long adc_en2; unsigned long adc_en2_mask; int (*adc_rate)(struct axp20x_adc_iio *info, int rate); @@ -910,7 +912,9 @@ static const struct axp_data axp20x_data = { .iio_info = &axp20x_adc_iio_info, .num_channels = ARRAY_SIZE(axp20x_adc_channels), .channels = axp20x_adc_channels, + .adc_en1 = AXP20X_ADC_EN1, .adc_en1_mask = AXP20X_ADC_EN1_MASK, + .adc_en2 = AXP20X_ADC_EN2, .adc_en2_mask = AXP20X_ADC_EN2_MASK, .adc_rate = axp20x_adc_rate, .maps = axp20x_maps, @@ -920,6 +924,7 @@ static const struct axp_data axp22x_data = { .iio_info = &axp22x_adc_iio_info, .num_channels = ARRAY_SIZE(axp22x_adc_channels), .channels = axp22x_adc_channels, + .adc_en1 = AXP20X_ADC_EN1, .adc_en1_mask = AXP22X_ADC_EN1_MASK, .adc_rate = axp22x_adc_rate, .maps = axp22x_maps, @@ -929,6 +934,7 @@ static const struct axp_data axp813_data = { .iio_info = &axp813_adc_iio_info, .num_channels = ARRAY_SIZE(axp813_adc_channels), .channels = axp813_adc_channels, + .adc_en1 = AXP20X_ADC_EN1, .adc_en1_mask = AXP22X_ADC_EN1_MASK, .adc_rate = axp813_adc_rate, .maps = axp22x_maps, @@ -988,14 +994,16 @@ static int axp20x_probe(struct platform_device *pdev) indio_dev->channels = info->data->channels; /* Enable the ADCs on IP */ - regmap_write(info->regmap, AXP20X_ADC_EN1, info->data->adc_en1_mask); + regmap_write(info->regmap, info->data->adc_en1, + info->data->adc_en1_mask); if (info->data->adc_en2_mask) - regmap_set_bits(info->regmap, AXP20X_ADC_EN2, + regmap_set_bits(info->regmap, info->data->adc_en2, info->data->adc_en2_mask); /* Configure ADCs rate */ - info->data->adc_rate(info, 100); + if (info->data->adc_rate) + info->data->adc_rate(info, 100); ret = iio_map_array_register(indio_dev, info->data->maps); if (ret < 0) { @@ -1015,10 +1023,10 @@ static int axp20x_probe(struct platform_device *pdev) iio_map_array_unregister(indio_dev); fail_map: - regmap_write(info->regmap, AXP20X_ADC_EN1, 0); + regmap_write(info->regmap, info->data->adc_en1, 0); if (info->data->adc_en2_mask) - regmap_write(info->regmap, AXP20X_ADC_EN2, 0); + regmap_write(info->regmap, info->data->adc_en2, 0); return ret; } @@ -1031,10 +1039,10 @@ static void axp20x_remove(struct platform_device *pdev) iio_device_unregister(indio_dev); iio_map_array_unregister(indio_dev); - regmap_write(info->regmap, AXP20X_ADC_EN1, 0); + regmap_write(info->regmap, info->data->adc_en1, 0); if (info->data->adc_en2_mask) - regmap_write(info->regmap, AXP20X_ADC_EN2, 0); + regmap_write(info->regmap, info->data->adc_en2, 0); } static struct platform_driver axp20x_adc_driver = { From patchwork Wed Aug 21 21:54:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13772163 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 415C0C52D7C for ; Wed, 21 Aug 2024 21:59:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=EOS6CB7c1t/IxbcoB65fP4OgyGzoOrEBpGmlG4zcGvM=; b=V8RyuF1nSoLgqKkp5vhtXEj2W/ Cqr/lPtg6w3fxY7uls4KMvJmTSshIDcx8lbD6f0a427DdFZoe6eQJ1QWcpJcqeqAHqVRw5tlh/SFI +impo2BpWnz9ebD6nE4sfhrG35kW4xWe3xNIwtqJGbUgOzN0l6d6lFvIS97kD+btZbYmF+0pCDXfx PHzFs/bjhY7Tn0JUg2criL7chrDHqWoTRSX+ktX9FZ97sgFZ5byJaRjTWRBee8KxkKN2+RudIHGxw uEHvYEGa7HlUvuCt4RRbTb9n8JOJCwaAuMmMO8Gk+ar792Vh0H399hjsen4eYnNtQ+quP4cXDrD5e 662U7woQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtMj-0000000AUWH-2hpw; Wed, 21 Aug 2024 21:59:41 +0000 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtKd-0000000AU3s-2u0B for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 21:57:33 +0000 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3db14930a1aso84670b6e.3 for ; Wed, 21 Aug 2024 14:57:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724277450; x=1724882250; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EOS6CB7c1t/IxbcoB65fP4OgyGzoOrEBpGmlG4zcGvM=; b=euB4Xlxpv5NGT/Frioe16L4tRbNCszREjmzftloRl99ZtvZ/TB5OgDoMqMAPCff4qu hYVLbfnl1208qBDO69BJA0Ezg5W8LNjTrAkwwBxgQnE7fwDKkaau2HlHc9YpLa1CxJcM WIvqZYjxleESjUibbw3d8CP0ZiZpdaKo49Ass15SvoN1vnUkjo1tHxbr3JkZztFLSer8 HJGFH/mqV+tjLgKFJ5dl1AIuzUvItVUnf0qCqgGltvQih32Uz6ry9Od4uuhur89F/ib2 /87jKdtixSF4LaH2k0/SDiRrwwm3+kFi3qEJ8siDYVmaPIIE9CskuE4NTTcAwK7ITfmv Xh6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724277450; x=1724882250; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EOS6CB7c1t/IxbcoB65fP4OgyGzoOrEBpGmlG4zcGvM=; b=Efu/2VgoTkatKZ8sz9sj1WlDgN+NKmdYVTG6cZgPPtexp+yZMB2A3zvqNapYmkRO4S tI1d3IxiE9S3Y4nKhxriHitkQ7PDmnEADJNv2iIVw6iR1DNGV6d4kMB+opuA41quNGaS Y5YSOpd7DinCM3cElw7UjJLhDvz3jWdxp8DuYNNwfG4dN5JPIxszTWzS2T08617lqQfJ EH/JStGN4OyAAfQikm1ZLMoJq9QphPycBpS9NFFNHExU+nfRs6DDAsud19j++tyM2+rg ylikdqSc6yP6PMVfwxcYEHAvInF5yQBcgpn5nnnuSlLkEGkl+GMV4SSvEeGxM4/WBl+7 sN3g== X-Forwarded-Encrypted: i=1; AJvYcCWinGglZG9tmxvrbe6Z2kpd9Gu74lJTbIy0YAu+cCAdVPjjkJim/1nYFrjPcfTP7V/GiYU5NNjl6CIiWaIv0jeR@lists.infradead.org X-Gm-Message-State: AOJu0Yws2qa1VqmilwYtjvTgvdt7OXIYbUeV4EwTspZ6GI+tAbOwchF9 P6HI6FC9KOvtYELh7pC3/DR0wcLp1bJO7TkjKg0J8tGDMTA3+a7a X-Google-Smtp-Source: AGHT+IEDEnpxMg/ftuWHkBCtoVjAbIZKtyzSllfCGKNLbkBb8Dpv1EHptRmC6SwkiV2S5+OBbV92Hw== X-Received: by 2002:a05:6808:1914:b0:3dd:32a3:76a4 with SMTP id 5614622812f47-3de194ed3dbmr5089953b6e.4.1724277450470; Wed, 21 Aug 2024 14:57:30 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf:81a9:2325:e0f7:7376]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225555b6sm47070b6e.17.2024.08.21.14.57.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 14:57:30 -0700 (PDT) From: Chris Morgan To: linux-sunxi@lists.linux.dev Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com, mripard@kernel.org, tgamblin@baylibre.com, aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de, lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, jic23@kernel.org, jonathan.cameron@huawei.com, Chris Morgan , Chen-Yu Tsai Subject: [PATCH V4 02/15] power: supply: axp20x_battery: Remove design from min and max voltage Date: Wed, 21 Aug 2024 16:54:43 -0500 Message-Id: <20240821215456.962564-3-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821215456.962564-1-macroalpha82@gmail.com> References: <20240821215456.962564-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_145731_737068_04CDF659 X-CRM114-Status: GOOD ( 13.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chris Morgan The POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN and POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN values should be immutable properties of the battery, but for this driver they are writable values and used as the minimum and maximum values for charging. Remove the DESIGN designation from these values. Fixes: 46c202b5f25f ("power: supply: add battery driver for AXP20X and AXP22X PMICs") Suggested-by: Chen-Yu Tsai Signed-off-by: Chris Morgan --- drivers/power/supply/axp20x_battery.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c index 6ac5c80cfda2..7520b599eb3d 100644 --- a/drivers/power/supply/axp20x_battery.c +++ b/drivers/power/supply/axp20x_battery.c @@ -303,11 +303,11 @@ static int axp20x_battery_get_prop(struct power_supply *psy, val->intval = reg & AXP209_FG_PERCENT; break; - case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: + case POWER_SUPPLY_PROP_VOLTAGE_MAX: return axp20x_batt->data->get_max_voltage(axp20x_batt, &val->intval); - case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: + case POWER_SUPPLY_PROP_VOLTAGE_MIN: ret = regmap_read(axp20x_batt->regmap, AXP20X_V_OFF, ®); if (ret) return ret; @@ -455,10 +455,10 @@ static int axp20x_battery_set_prop(struct power_supply *psy, struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy); switch (psp) { - case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: + case POWER_SUPPLY_PROP_VOLTAGE_MIN: return axp20x_set_voltage_min_design(axp20x_batt, val->intval); - case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: + case POWER_SUPPLY_PROP_VOLTAGE_MAX: return axp20x_batt->data->set_max_voltage(axp20x_batt, val->intval); case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: @@ -493,8 +493,8 @@ static enum power_supply_property axp20x_battery_props[] = { POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, POWER_SUPPLY_PROP_HEALTH, - POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, - POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, + POWER_SUPPLY_PROP_VOLTAGE_MAX, + POWER_SUPPLY_PROP_VOLTAGE_MIN, POWER_SUPPLY_PROP_CAPACITY, }; @@ -502,8 +502,8 @@ static int axp20x_battery_prop_writeable(struct power_supply *psy, enum power_supply_property psp) { return psp == POWER_SUPPLY_PROP_STATUS || - psp == POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN || - psp == POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN || + psp == POWER_SUPPLY_PROP_VOLTAGE_MIN || + psp == POWER_SUPPLY_PROP_VOLTAGE_MAX || psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT || psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX; } From patchwork Wed Aug 21 21:54:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13772181 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5BC97C52D6F for ; Wed, 21 Aug 2024 22:00:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=w6uKad2/4G0gY3Nm8pi2ZP0lDyan1DAsdC6ygDIyfJY=; b=JG9agpB0mYvbUBsXlqwu7JXliE bIn2gvZCRCzi7u8YXstaWbAysf7cq9X5svOP3WghuxvOQbjt0BpLek/cDKmw5oxMod5avT1F1wzqB z8bNwBd321rYFoERKhaNu1074USwrRNf1M//zdcyTCUvg1tDP/7vdTjqh0y9b3be+SX7o9y8X/ZeQ Lw/e9clu0cRv/bPEx9PiW8aht9ESL8/90Z3fSgWgfWYYsCBpaDU9ePAPYEF3MlnukUz79Hr+7cDGI nAXHSEM/YppoSZiWRhYIw9xAqqiRxVQWRioh+BKFXbxPHTnVx0mkpFNlhG+KZ5H5aZ+hvpmWG3Vo8 0XSqalgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtNP-0000000AUbl-2Gyh; Wed, 21 Aug 2024 22:00:23 +0000 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtKf-0000000AU4P-0k5s for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 21:57:34 +0000 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3db16b2c1d2so86572b6e.2 for ; Wed, 21 Aug 2024 14:57:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724277451; x=1724882251; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=w6uKad2/4G0gY3Nm8pi2ZP0lDyan1DAsdC6ygDIyfJY=; b=X4stz7w31hlolQ2ksb1eH9Q46REFWu5SIzPi95Bcfhku101n/sGk+oAp9Cj6f81GpW uW+qoaqNPe2OkU7sVS8x4yl9o3qASqFZfIgUbPLniUfkJEeXMUB65/gaxynS9VPGGV5f ZXvtXdZSVkAR+dJnVPHk8YvAfnGXJVmG/wUO0qJ7aok8uVthx2pX5dKhJAVQRw4o9zsV tDa/cjkKUayfwVU0nqRJ+fkGYaBGMyHrRbVltd5nodN9bmhKA9OYaCI8+OiUhBa4Vf4A xKz92g58XuNVS0dDEXZSHmwqwEkdw2inwo2xZ3L9B8xm/GADoD3MQ+uWtvTwdeIY2/Zx Y66A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724277451; x=1724882251; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w6uKad2/4G0gY3Nm8pi2ZP0lDyan1DAsdC6ygDIyfJY=; b=elB8wp7FZbFpj1bKV9ycYK63OeCmYsV9EBFkKe0276/IMs2lLy37FBnwwbI3d55Uhx EVA1Je0ibDZuRhcEm/5XHpyxgxEnu2UlAR7vAOhQJpTLXL7gkBUscyzGbYpwQeYlmIji f+Isf8rin3hilbRErnFTQ85rsc7+DKJxF6uvdpfB/SE+Z2K3P5F45PXKA5Sn2iZI6EW1 tf4YR1CZS8dP7ElpsxMeRPoIRFPG6fT9MD4m/br3l9Munx0OfVoDUENgo7nObmXETcnj SLlUcDS2rArgDoMIs9MrKrJxR7rFNAq3P7vLq16WR4u3N6ZdoorzOaVp2PKd0SMnwny8 rT+A== X-Forwarded-Encrypted: i=1; AJvYcCWLC5OkfEBo4MdsKRWa+0lqS6sHLPqNqZ3HJOB7YH1YOH67lkMpoXQ/Qn8CnyLLNPjFVU1ADQ8Mf7HHSoV+40zI@lists.infradead.org X-Gm-Message-State: AOJu0Yx9dosig+TnVT+1CXWIef18blevq4bwZ/2rrYAf/pSIXu2OpDQF R566h2JluFoXzs/SOCo8hxa5Kz6K14Y9IbPJzZrAjZTbPxnNArB/ X-Google-Smtp-Source: AGHT+IEFFJbziMrJiWeCFL1hwf2ttRLRClqnubICMWhVvCR17fO+nze7N86057SdvUBo7gsUsXy5LA== X-Received: by 2002:a05:6808:1910:b0:3d9:2b5a:4ac6 with SMTP id 5614622812f47-3de194eb972mr5016464b6e.6.1724277451289; Wed, 21 Aug 2024 14:57:31 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf:81a9:2325:e0f7:7376]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225555b6sm47070b6e.17.2024.08.21.14.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 14:57:30 -0700 (PDT) From: Chris Morgan To: linux-sunxi@lists.linux.dev Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com, mripard@kernel.org, tgamblin@baylibre.com, aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de, lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, jic23@kernel.org, jonathan.cameron@huawei.com, Chris Morgan Subject: [PATCH V4 03/15] power: supply: axp20x_battery: Make iio and battery config per device Date: Wed, 21 Aug 2024 16:54:44 -0500 Message-Id: <20240821215456.962564-4-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821215456.962564-1-macroalpha82@gmail.com> References: <20240821215456.962564-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_145733_376273_F5B427E5 X-CRM114-Status: GOOD ( 23.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chris Morgan Move the configuration of battery specific information and available iio channels from the probe function to a device specific routine, allowing us to use this driver for devices with slightly different configurations (such as the AXP717). Signed-off-by: Chris Morgan --- drivers/power/supply/axp20x_battery.c | 137 +++++++++++++++++--------- 1 file changed, 88 insertions(+), 49 deletions(-) diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c index 7520b599eb3d..c903c588b361 100644 --- a/drivers/power/supply/axp20x_battery.c +++ b/drivers/power/supply/axp20x_battery.c @@ -58,11 +58,19 @@ struct axp20x_batt_ps; struct axp_data { - int ccc_scale; - int ccc_offset; - bool has_fg_valid; + int ccc_scale; + int ccc_offset; + unsigned int ccc_reg; + unsigned int ccc_mask; + bool has_fg_valid; + const struct power_supply_desc *bat_ps_desc; int (*get_max_voltage)(struct axp20x_batt_ps *batt, int *val); int (*set_max_voltage)(struct axp20x_batt_ps *batt, int val); + int (*cfg_iio_chan)(struct platform_device *pdev, + struct axp20x_batt_ps *axp_batt); + void (*set_bat_info)(struct platform_device *pdev, + struct axp20x_batt_ps *axp_batt, + struct power_supply_battery_info *info); }; struct axp20x_batt_ps { @@ -508,7 +516,7 @@ static int axp20x_battery_prop_writeable(struct power_supply *psy, psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX; } -static const struct power_supply_desc axp20x_batt_ps_desc = { +static const struct power_supply_desc axp209_batt_ps_desc = { .name = "axp20x-battery", .type = POWER_SUPPLY_TYPE_BATTERY, .properties = axp20x_battery_props, @@ -518,27 +526,94 @@ static const struct power_supply_desc axp20x_batt_ps_desc = { .set_property = axp20x_battery_set_prop, }; +static int axp209_bat_cfg_iio_channels(struct platform_device *pdev, + struct axp20x_batt_ps *axp_batt) +{ + axp_batt->batt_v = devm_iio_channel_get(&pdev->dev, "batt_v"); + if (IS_ERR(axp_batt->batt_v)) { + if (PTR_ERR(axp_batt->batt_v) == -ENODEV) + return -EPROBE_DEFER; + return PTR_ERR(axp_batt->batt_v); + } + + axp_batt->batt_chrg_i = devm_iio_channel_get(&pdev->dev, + "batt_chrg_i"); + if (IS_ERR(axp_batt->batt_chrg_i)) { + if (PTR_ERR(axp_batt->batt_chrg_i) == -ENODEV) + return -EPROBE_DEFER; + return PTR_ERR(axp_batt->batt_chrg_i); + } + + axp_batt->batt_dischrg_i = devm_iio_channel_get(&pdev->dev, + "batt_dischrg_i"); + if (IS_ERR(axp_batt->batt_dischrg_i)) { + if (PTR_ERR(axp_batt->batt_dischrg_i) == -ENODEV) + return -EPROBE_DEFER; + return PTR_ERR(axp_batt->batt_dischrg_i); + } + + return 0; +} + +static void axp209_set_battery_info(struct platform_device *pdev, + struct axp20x_batt_ps *axp_batt, + struct power_supply_battery_info *info) +{ + int vmin = info->voltage_min_design_uv; + int ccc = info->constant_charge_current_max_ua; + + if (vmin > 0 && axp20x_set_voltage_min_design(axp_batt, vmin)) + dev_err(&pdev->dev, + "couldn't set voltage_min_design\n"); + + /* Set max to unverified value to be able to set CCC */ + axp_batt->max_ccc = ccc; + + if (ccc <= 0 || axp20x_set_constant_charge_current(axp_batt, ccc)) { + dev_err(&pdev->dev, + "couldn't set ccc from DT: fallback to min value\n"); + ccc = 300000; + axp_batt->max_ccc = ccc; + axp20x_set_constant_charge_current(axp_batt, ccc); + } +} + static const struct axp_data axp209_data = { .ccc_scale = 100000, .ccc_offset = 300000, + .ccc_reg = AXP20X_CHRG_CTRL1, + .ccc_mask = AXP20X_CHRG_CTRL1_TGT_CURR, + .bat_ps_desc = &axp209_batt_ps_desc, .get_max_voltage = axp20x_battery_get_max_voltage, .set_max_voltage = axp20x_battery_set_max_voltage, + .cfg_iio_chan = axp209_bat_cfg_iio_channels, + .set_bat_info = axp209_set_battery_info, }; static const struct axp_data axp221_data = { .ccc_scale = 150000, .ccc_offset = 300000, + .ccc_reg = AXP20X_CHRG_CTRL1, + .ccc_mask = AXP20X_CHRG_CTRL1_TGT_CURR, .has_fg_valid = true, + .bat_ps_desc = &axp209_batt_ps_desc, .get_max_voltage = axp22x_battery_get_max_voltage, .set_max_voltage = axp22x_battery_set_max_voltage, + .cfg_iio_chan = axp209_bat_cfg_iio_channels, + .set_bat_info = axp209_set_battery_info, }; static const struct axp_data axp813_data = { .ccc_scale = 200000, .ccc_offset = 200000, + .ccc_reg = AXP20X_CHRG_CTRL1, + .ccc_mask = AXP20X_CHRG_CTRL1_TGT_CURR, .has_fg_valid = true, + .bat_ps_desc = &axp209_batt_ps_desc, .get_max_voltage = axp813_battery_get_max_voltage, .set_max_voltage = axp20x_battery_set_max_voltage, + .cfg_iio_chan = axp209_bat_cfg_iio_channels, + .set_bat_info = axp209_set_battery_info, }; static const struct of_device_id axp20x_battery_ps_id[] = { @@ -561,6 +636,7 @@ static int axp20x_power_probe(struct platform_device *pdev) struct power_supply_config psy_cfg = {}; struct power_supply_battery_info *info; struct device *dev = &pdev->dev; + int ret; if (!of_device_is_available(pdev->dev.of_node)) return -ENODEV; @@ -572,29 +648,6 @@ static int axp20x_power_probe(struct platform_device *pdev) axp20x_batt->dev = &pdev->dev; - axp20x_batt->batt_v = devm_iio_channel_get(&pdev->dev, "batt_v"); - if (IS_ERR(axp20x_batt->batt_v)) { - if (PTR_ERR(axp20x_batt->batt_v) == -ENODEV) - return -EPROBE_DEFER; - return PTR_ERR(axp20x_batt->batt_v); - } - - axp20x_batt->batt_chrg_i = devm_iio_channel_get(&pdev->dev, - "batt_chrg_i"); - if (IS_ERR(axp20x_batt->batt_chrg_i)) { - if (PTR_ERR(axp20x_batt->batt_chrg_i) == -ENODEV) - return -EPROBE_DEFER; - return PTR_ERR(axp20x_batt->batt_chrg_i); - } - - axp20x_batt->batt_dischrg_i = devm_iio_channel_get(&pdev->dev, - "batt_dischrg_i"); - if (IS_ERR(axp20x_batt->batt_dischrg_i)) { - if (PTR_ERR(axp20x_batt->batt_dischrg_i) == -ENODEV) - return -EPROBE_DEFER; - return PTR_ERR(axp20x_batt->batt_dischrg_i); - } - axp20x_batt->regmap = dev_get_regmap(pdev->dev.parent, NULL); platform_set_drvdata(pdev, axp20x_batt); @@ -603,8 +656,12 @@ static int axp20x_power_probe(struct platform_device *pdev) axp20x_batt->data = (struct axp_data *)of_device_get_match_data(dev); + ret = axp20x_batt->data->cfg_iio_chan(pdev, axp20x_batt); + if (ret) + return ret; + axp20x_batt->batt = devm_power_supply_register(&pdev->dev, - &axp20x_batt_ps_desc, + axp20x_batt->data->bat_ps_desc, &psy_cfg); if (IS_ERR(axp20x_batt->batt)) { dev_err(&pdev->dev, "failed to register power supply: %ld\n", @@ -613,33 +670,15 @@ static int axp20x_power_probe(struct platform_device *pdev) } if (!power_supply_get_battery_info(axp20x_batt->batt, &info)) { - int vmin = info->voltage_min_design_uv; - int ccc = info->constant_charge_current_max_ua; - - if (vmin > 0 && axp20x_set_voltage_min_design(axp20x_batt, - vmin)) - dev_err(&pdev->dev, - "couldn't set voltage_min_design\n"); - - /* Set max to unverified value to be able to set CCC */ - axp20x_batt->max_ccc = ccc; - - if (ccc <= 0 || axp20x_set_constant_charge_current(axp20x_batt, - ccc)) { - dev_err(&pdev->dev, - "couldn't set constant charge current from DT: fallback to minimum value\n"); - ccc = 300000; - axp20x_batt->max_ccc = ccc; - axp20x_set_constant_charge_current(axp20x_batt, ccc); - } + axp20x_batt->data->set_bat_info(pdev, axp20x_batt, info); + power_supply_put_battery_info(axp20x_batt->batt, info); } /* * Update max CCC to a valid value if battery info is present or set it * to current register value by default. */ - axp20x_get_constant_charge_current(axp20x_batt, - &axp20x_batt->max_ccc); + axp20x_get_constant_charge_current(axp20x_batt, &axp20x_batt->max_ccc); return 0; } From patchwork Wed Aug 21 21:54:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13772183 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 064F8C52D6F for ; Wed, 21 Aug 2024 22:01:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=I0UhxZ2XxQFgvUjgiU5dDgFB2D6T8k8pYUXnFuEDKNs=; b=uN67GzgjxN2SZAMm41lFQ6h+6/ GlEo6QUOoMGKzc8XzPQgvwSKoJ+8dxY6Vxva2ZmaCtfy1Iz3VJvjc3xKFywoOT21u9WZjk8qS2N7d Li1JycsomsN+Oogk/TzU+N0thJh6b1sv8Yvn7Naquyem7K1s/ndl6C0siRY1mpb1Eb0S30g42KamO UVX9tpK44S1dVKGKnYowS8UZZtdCZTmfhowNZUDdzhUUDVgN+DVK8sHaxHb99dIDR30ohNl2vB7g/ A1P9x2LtBlPJ08Z2UbLf83eB6Z2SCcekfp+7KpwE0OdUrCgPD7l15ISJSoaUxyWB9+UIxLmsog+NT E/7YPBaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtOm-0000000AUrq-42cR; Wed, 21 Aug 2024 22:01:48 +0000 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtKf-0000000AU50-1i4p for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 21:57:35 +0000 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-3db1e4219f8so73116b6e.3 for ; Wed, 21 Aug 2024 14:57:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724277452; x=1724882252; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=I0UhxZ2XxQFgvUjgiU5dDgFB2D6T8k8pYUXnFuEDKNs=; b=cSA/1wTNM2xGNM++On2J2OX8JFrkGB0a7hiS3NzCr6pOMQDoDsNn93rCr5rdkhkZHX meltFJNjX4v4zKdiJQiWM91ZxZqY3FiZVobP4z0DBoyIzqXxhn3I2T4UL5m2Kh3Xmj7Z ys4al/iMgKXL1C3HQNDYPvIC/yPLOj1c+52Kj4VC9lUnT3GuCX4o41CDf34Tf5kk6joI R0vFMEfTa2hoEjglt9Mr1kSXwsZpmo0L0yUfuRSBq37k83l7DVuLRjd9S1g/5lmfUxOP bFn3VlaI3La04sxfEBDxqXBwl69sgnN8O7kbsjnSnp0K3rU6XcWSI3XkmIXEsyADStB3 +gEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724277452; x=1724882252; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I0UhxZ2XxQFgvUjgiU5dDgFB2D6T8k8pYUXnFuEDKNs=; b=QRydWBeE7l/0IEPvjPWjA/7Vcp4YdPERBmI8n747U5bGN0vO1JJJTxg2BerZ/ACQbf E9KS6SKYTOZd/R7Z1zpEHFYIkdfN+8SvS79+GdBR3V5AjdPkbfV3Vj2DUrm4OwAxi9uD uovBOE5wEKwAc419B9IJsFkGZU6pX2yTr2aXe1Mb+FnwY9w7BYZTRLHtbOwUA7cE9Z6r QXRC1AEFrVPeua3qKeVsn43Uz2VB5sUr99TER1T6eSelQdq4DCPsx4t1HG4wdpsNcv/R dFsKwoFey7+h8XOnIW/i4RCeEFDbfZpRi8yzWjiHyQzzxenu35OzpPMmPp2IzSXWVzny Yn1A== X-Forwarded-Encrypted: i=1; AJvYcCWaI3mF/cZ5ktOqjjYEYuAi6Qz/3lDFJXM/yq+Ls97lp30qBrcQCkHFZQLzwUHLx2Vgv+OTG5b5gYn/KqXSHhhd@lists.infradead.org X-Gm-Message-State: AOJu0YxF+LiGL+zl8/ww29gvrLNVNfi4IUoaVu/1lWo3eGCFdQoKVrxZ zDKRHDO7BvaHsS5G4XKeWRxOkINZ4K/j6pNJ8y+mbi2/zM9OY8HM X-Google-Smtp-Source: AGHT+IG0XI2TE/eI97M843RE/qlc7osFS8BEftni9pYq41Isvj2l2mBUFv5vVdUHIaSBnu9JP0w/Sw== X-Received: by 2002:a05:6808:1142:b0:3db:1661:4d64 with SMTP id 5614622812f47-3de194f34a2mr4379695b6e.13.1724277452201; Wed, 21 Aug 2024 14:57:32 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf:81a9:2325:e0f7:7376]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225555b6sm47070b6e.17.2024.08.21.14.57.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 14:57:31 -0700 (PDT) From: Chris Morgan To: linux-sunxi@lists.linux.dev Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com, mripard@kernel.org, tgamblin@baylibre.com, aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de, lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, jic23@kernel.org, jonathan.cameron@huawei.com, Chris Morgan Subject: [PATCH V4 04/15] power: supply: axp20x_usb_power: Make VBUS and IIO config per device Date: Wed, 21 Aug 2024 16:54:45 -0500 Message-Id: <20240821215456.962564-5-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821215456.962564-1-macroalpha82@gmail.com> References: <20240821215456.962564-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_145733_478653_875FBE02 X-CRM114-Status: GOOD ( 18.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chris Morgan Make reading of the vbus value and configuring of the iio channels device specific, to allow additional devices (such as the AXP717) to be supported by this driver. Signed-off-by: Chris Morgan --- drivers/power/supply/axp20x_usb_power.c | 87 +++++++++++++++---------- 1 file changed, 54 insertions(+), 33 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index dae7e5cfc54e..cd9e92f2ce71 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -45,6 +45,8 @@ */ #define DEBOUNCE_TIME msecs_to_jiffies(50) +struct axp20x_usb_power; + struct axp_data { const struct power_supply_desc *power_desc; const char * const *irq_names; @@ -58,6 +60,10 @@ struct axp_data { struct reg_field usb_bc_det_fld; struct reg_field vbus_disable_bit; bool vbus_needs_polling: 1; + void (*axp20x_read_vbus)(struct work_struct *work); + int (*axp20x_cfg_iio_chan)(struct platform_device *pdev, + struct axp20x_usb_power *power); + int (*axp20x_cfg_adc_reg)(struct axp20x_usb_power *power); }; struct axp20x_usb_power { @@ -385,6 +391,36 @@ static int axp20x_usb_power_prop_writeable(struct power_supply *psy, psp == POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT; } +static int axp20x_configure_iio_channels(struct platform_device *pdev, + struct axp20x_usb_power *power) +{ + power->vbus_v = devm_iio_channel_get(&pdev->dev, "vbus_v"); + if (IS_ERR(power->vbus_v)) { + if (PTR_ERR(power->vbus_v) == -ENODEV) + return -EPROBE_DEFER; + return PTR_ERR(power->vbus_v); + } + + power->vbus_i = devm_iio_channel_get(&pdev->dev, "vbus_i"); + if (IS_ERR(power->vbus_i)) { + if (PTR_ERR(power->vbus_i) == -ENODEV) + return -EPROBE_DEFER; + return PTR_ERR(power->vbus_i); + } + + return 0; +} + +static int axp20x_configure_adc_registers(struct axp20x_usb_power *power) +{ + /* Enable vbus voltage and current measurement */ + return regmap_update_bits(power->regmap, AXP20X_ADC_EN1, + AXP20X_ADC_EN1_VBUS_CURR | + AXP20X_ADC_EN1_VBUS_VOLT, + AXP20X_ADC_EN1_VBUS_CURR | + AXP20X_ADC_EN1_VBUS_VOLT); +} + static enum power_supply_property axp20x_usb_power_properties[] = { POWER_SUPPLY_PROP_HEALTH, POWER_SUPPLY_PROP_PRESENT, @@ -505,6 +541,9 @@ static const struct axp_data axp192_data = { .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), .vbus_valid_bit = REG_FIELD(AXP192_USB_OTG_STATUS, 2, 2), .vbus_mon_bit = REG_FIELD(AXP20X_VBUS_MON, 3, 3), + .axp20x_read_vbus = &axp20x_usb_power_poll_vbus, + .axp20x_cfg_iio_chan = axp20x_configure_iio_channels, + .axp20x_cfg_adc_reg = axp20x_configure_adc_registers, }; static const struct axp_data axp202_data = { @@ -516,6 +555,9 @@ static const struct axp_data axp202_data = { .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), .vbus_valid_bit = REG_FIELD(AXP20X_USB_OTG_STATUS, 2, 2), .vbus_mon_bit = REG_FIELD(AXP20X_VBUS_MON, 3, 3), + .axp20x_read_vbus = &axp20x_usb_power_poll_vbus, + .axp20x_cfg_iio_chan = axp20x_configure_iio_channels, + .axp20x_cfg_adc_reg = axp20x_configure_adc_registers, }; static const struct axp_data axp221_data = { @@ -526,6 +568,9 @@ static const struct axp_data axp221_data = { .curr_lim_table_size = ARRAY_SIZE(axp221_usb_curr_lim_table), .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), .vbus_needs_polling = true, + .axp20x_read_vbus = &axp20x_usb_power_poll_vbus, + .axp20x_cfg_iio_chan = axp20x_configure_iio_channels, + .axp20x_cfg_adc_reg = axp20x_configure_adc_registers, }; static const struct axp_data axp223_data = { @@ -536,6 +581,9 @@ static const struct axp_data axp223_data = { .curr_lim_table_size = ARRAY_SIZE(axp20x_usb_curr_lim_table), .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), .vbus_needs_polling = true, + .axp20x_read_vbus = &axp20x_usb_power_poll_vbus, + .axp20x_cfg_iio_chan = axp20x_configure_iio_channels, + .axp20x_cfg_adc_reg = axp20x_configure_adc_registers, }; static const struct axp_data axp813_data = { @@ -549,6 +597,9 @@ static const struct axp_data axp813_data = { .usb_bc_det_fld = REG_FIELD(AXP288_BC_DET_STAT, 5, 7), .vbus_disable_bit = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7), .vbus_needs_polling = true, + .axp20x_read_vbus = &axp20x_usb_power_poll_vbus, + .axp20x_cfg_iio_chan = axp20x_configure_iio_channels, + .axp20x_cfg_adc_reg = axp20x_configure_adc_registers, }; #ifdef CONFIG_PM_SLEEP @@ -590,36 +641,6 @@ static int axp20x_usb_power_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(axp20x_usb_power_pm_ops, axp20x_usb_power_suspend, axp20x_usb_power_resume); -static int configure_iio_channels(struct platform_device *pdev, - struct axp20x_usb_power *power) -{ - power->vbus_v = devm_iio_channel_get(&pdev->dev, "vbus_v"); - if (IS_ERR(power->vbus_v)) { - if (PTR_ERR(power->vbus_v) == -ENODEV) - return -EPROBE_DEFER; - return PTR_ERR(power->vbus_v); - } - - power->vbus_i = devm_iio_channel_get(&pdev->dev, "vbus_i"); - if (IS_ERR(power->vbus_i)) { - if (PTR_ERR(power->vbus_i) == -ENODEV) - return -EPROBE_DEFER; - return PTR_ERR(power->vbus_i); - } - - return 0; -} - -static int configure_adc_registers(struct axp20x_usb_power *power) -{ - /* Enable vbus voltage and current measurement */ - return regmap_update_bits(power->regmap, AXP20X_ADC_EN1, - AXP20X_ADC_EN1_VBUS_CURR | - AXP20X_ADC_EN1_VBUS_VOLT, - AXP20X_ADC_EN1_VBUS_CURR | - AXP20X_ADC_EN1_VBUS_VOLT); -} - static int axp20x_regmap_field_alloc_optional(struct device *dev, struct regmap *regmap, struct reg_field fdesc, @@ -707,7 +728,7 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) return ret; ret = devm_delayed_work_autocancel(&pdev->dev, &power->vbus_detect, - axp20x_usb_power_poll_vbus); + axp_data->axp20x_read_vbus); if (ret) return ret; @@ -718,9 +739,9 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) return ret; if (IS_ENABLED(CONFIG_AXP20X_ADC)) - ret = configure_iio_channels(pdev, power); + ret = axp_data->axp20x_cfg_iio_chan(pdev, power); else - ret = configure_adc_registers(power); + ret = axp_data->axp20x_cfg_adc_reg(power); if (ret) return ret; From patchwork Wed Aug 21 21:54:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13772182 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 292CEC52D7C for ; Wed, 21 Aug 2024 22:01:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=QGxHVYptl/mfZ5O11htImf9Dey/T9TeFYQkFJXrtkIg=; b=XIL76Ydf7bisRiW0qG4ArnZGgH cxmdYccUAOEZTaaPs0Y9foOklP+AF4O4Bvnn9iLiavpuaBQ5YKUQeSE2axZhjoxHlQ9YyJbVdKCNN iyGuS1FcJOtta2Cgqa1P29xJylu/XyqgwGxIZCWMtq8s7oEvGZ1HemIvuuhXE3s4s/TJ6qIixKeNd hsXuAVOCSMI8qsk2SOqj3ngf3+4UCHBGQPiq1peCkf3fLVBRQ+Out+ZKw86D2LhGMxEVTh3oRbSPO WLfOdFgmulL0lU8O5B2ejdxTWBgx89PxkqMrihZgrabR6/SheYcw4DM+GGEzm2g+MZAXgnEI0tMj8 NCY9bjWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtO6-0000000AUip-1Ojh; Wed, 21 Aug 2024 22:01:06 +0000 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtKf-0000000AU5D-2tI9 for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 21:57:35 +0000 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3db23a608eeso95276b6e.1 for ; Wed, 21 Aug 2024 14:57:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724277453; x=1724882253; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QGxHVYptl/mfZ5O11htImf9Dey/T9TeFYQkFJXrtkIg=; b=hFs0OChm0IlwfQ8rabkMGEsbYoBp4FK15+IHeDfAk8VJ918ouxGCtfoae2d2xQLsgK eajj7S/4+5xjXGc8OZIv4milvqyTbiY9b35nhQxuz49nIMh0tOvvBLcL6sXQiDBO+qX5 Z1+u3+RpyqfoDnrLfy4H2wa9+5slqC9ik3HfQX9fdvUW7o6ZKzq3AHWY8W4DlFuOtUN7 yfjG71ESj2RYT1TeJKkN8zza94BGTn8mGBMjUNQokaxYdMET/uldbyfGgdfGhNAWfiIC jLLVnBhJwVKBG4GoX41gUC9lOjDzygDNOJkqhcXNRm+Bc8mg2cUjezbv1MZoXxrVrP6a Pbdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724277453; x=1724882253; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QGxHVYptl/mfZ5O11htImf9Dey/T9TeFYQkFJXrtkIg=; b=XbqSeZsrayz2V+pxTYEbLRBENUbmfwBs1nGPSWngY/RTo+w21cW3euRk8jH3y6T1Re gr9TrCKDmQbdY5NaGm9DdULlVOMFnn4QY+8kBRmZGypPuAf62SrgabtRky4XxAe+g0ij 6eFRdC8jkq6v29lrpDHGaWEOmdRtzNf5Ww2UrjcY4bIB8o3/FjYJZRXEiDEmxHuXJWLk zOyK8YFjt5eEHrveej5mFtxUZqE4IYJar03H6JjuW9Y3uzOyAHus/ZCSfZUYTkfRrD2d jvuK0UKSnXxVhfKpk9qBdykZA4vgUbNfWIurTve3le8bGq3M2aBRpyYeplLREvT3qYDN P9pg== X-Forwarded-Encrypted: i=1; AJvYcCVIeq2SBkTBxeaUL3unyjP4LEBPS0pqCY0Z5dSoWv3wZk5QWGfQLHFQu5jOVnjCfE+R3ORGvedsbAxYzUtBwNY3@lists.infradead.org X-Gm-Message-State: AOJu0YwHoDx25+GYY8hMqR8AI0Skrd4STD1dUnf/4t9u1D6MZMFI2bar AslY9uNSxuaA+Yz3fudal2RDa9bMmvwlnu6cGFjLM30OJankC3+3 X-Google-Smtp-Source: AGHT+IEEVh05GQZqcfbn4IDKx4nQgV7t9q/7T+7lh7gib4DsRCbvqlfs8kaWytyaNhMT/Lx2z5jZKg== X-Received: by 2002:a05:6808:2f08:b0:3de:220c:ace2 with SMTP id 5614622812f47-3de220cae0amr601913b6e.14.1724277452915; Wed, 21 Aug 2024 14:57:32 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf:81a9:2325:e0f7:7376]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225555b6sm47070b6e.17.2024.08.21.14.57.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 14:57:32 -0700 (PDT) From: Chris Morgan To: linux-sunxi@lists.linux.dev Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com, mripard@kernel.org, tgamblin@baylibre.com, aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de, lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, jic23@kernel.org, jonathan.cameron@huawei.com, Chris Morgan Subject: [PATCH V4 05/15] dt-bindings: power: supply: axp20x: Add input-current-limit-microamp Date: Wed, 21 Aug 2024 16:54:46 -0500 Message-Id: <20240821215456.962564-6-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821215456.962564-1-macroalpha82@gmail.com> References: <20240821215456.962564-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_145733_812975_9DC7DA38 X-CRM114-Status: GOOD ( 12.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chris Morgan Allow specifying a hard limit of the maximum input current. Some PMICs such as the AXP717 can pull up to 3.25A, so allow a value to be specified that clamps this in the event the hardware is not designed for it. Signed-off-by: Chris Morgan Reviewed-by: Krzysztof Kozlowski --- .../x-powers,axp20x-usb-power-supply.yaml | 58 ++++++++++++++++++- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml index 34b7959d6772..ab24ebf2852f 100644 --- a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml +++ b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml @@ -15,9 +15,6 @@ maintainers: - Chen-Yu Tsai - Sebastian Reichel -allOf: - - $ref: power-supply.yaml# - properties: compatible: oneOf: @@ -31,8 +28,63 @@ properties: - const: x-powers,axp803-usb-power-supply - const: x-powers,axp813-usb-power-supply + input-current-limit-microamp: + description: + Optional value to clamp the maximum input current limit to for + the device. If omitted, the programmed value from the EFUSE will + be used. + minimum: 100000 + maximum: 4000000 required: - compatible +allOf: + - $ref: power-supply.yaml# + - if: + properties: + compatible: + contains: + enum: + - x-powers,axp192-usb-power-supply + then: + properties: + input-current-limit-microamp: + enum: [100000, 500000] + + - if: + properties: + compatible: + contains: + enum: + - x-powers,axp202-usb-power-supply + - x-powers,axp223-usb-power-supply + then: + properties: + input-current-limit-microamp: + enum: [100000, 500000, 900000] + + - if: + properties: + compatible: + contains: + enum: + - x-powers,axp221-usb-power-supply + then: + properties: + input-current-limit-microamp: + enum: [500000, 900000] + + - if: + properties: + compatible: + contains: + enum: + - x-powers,axp813-usb-power-supply + then: + properties: + input-current-limit-microamp: + enum: [100000, 500000, 900000, 1500000, 2000000, 2500000, + 3000000, 3500000, 4000000] + additionalProperties: false From patchwork Wed Aug 21 21:54:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13772184 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 04845C52D6F for ; Wed, 21 Aug 2024 22:02:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=VW8pLbjHmp58tJfvrusMBZ0t6nfvqNtc57mmOOIaTIw=; b=oiXAvl3qEuOcYqwILo998wiUHm rvJ8EvOxwx0C4JkEh+BCNBAhQN2AwYllRzR8Fjbrr27BwTOx3z8EOw2LkZSZgJAB/YVHuFf0uTp+K ivJMgBXHGNQVMBbI+eftHSiG6tMW6VajCkdjnAVKKnTyIuy/r8yePf13qjLIqcbEnBzdSkBVTb9bS kajsGd0jaxy4En+U8y0iP3gNr0+/2KtY6TNGw0YQzuEkCf1H6D4e2aJ1/mOiV05xjnIDcRRbvQye5 zR+MZxsV753wIGpN4gN5I9uP0jfsev8GSrgSGRw5356aU0yzAKZOMoOGViCOteVIg1xRwi0IM9nVq +VOOTQBg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtPT-0000000AUyg-2kEd; Wed, 21 Aug 2024 22:02:31 +0000 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtKg-0000000AU5y-1UUw for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 21:57:35 +0000 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3de13d6bdcaso54911b6e.2 for ; Wed, 21 Aug 2024 14:57:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724277453; x=1724882253; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VW8pLbjHmp58tJfvrusMBZ0t6nfvqNtc57mmOOIaTIw=; b=Wl00aK2rg0hIRMyANHz2Y3FwYpIqoXql7KrDmdHLcffGZFP3rqLWF0UWoKl4b+F/RJ aEMyzvicUMtbLqtLFzUSjs1YTigm/1h65WiyxuVU5QAJXCl8icKkkDSr3sHKfiNCnalQ NgUS2G5Ngz8LItsrRn9wnJUiwZ3NUmg7+SvQDZuj7ryEEjqiEeudKhu9+3Sj7lmRgCya HTe5OOtHmeeIlGpayUwJLP8DBU0pFMYXCwIAIMy0kxWjui/k0t0gWItbmJUL8ll7k8pp mXQ0M148uQs4CHyomUl13xui/HNjaIAf1XEdKmZk2IoOQvkufT47uxT+TcNZ3OKE0ckd +7vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724277453; x=1724882253; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VW8pLbjHmp58tJfvrusMBZ0t6nfvqNtc57mmOOIaTIw=; b=cpklxjcZHH0e8fFN056r1QmQDlQqNKRXnKO1sQ+leZxBAEF/8zhY0h4QaM8qE8M+tK HqHWRlNchRg0FHqjbefq85qJChdCkUpcMrMOmgIYIOGm7c5EmwbZOhItXeINFqjetBwy WiSk+qpgIOMVvCRngMy2s3aKIjsKoZ9IEhq47O+K22DyeExDwkp5Cyi84hmNogTKaK8t 2bans80hs7RHg8tpHTDyo1mOiO5kVQrIRWLFti/fTwiuqr0069yxAl5psUi7nDjmfdY2 iANT93OoUVMgPalxjVc3v0gWsjOfhzfL8ILjV/2MksChSLzwok1W08CT+QOhehZF8tyl qVaw== X-Forwarded-Encrypted: i=1; AJvYcCW1/AgV01uZnS9Gw5ikiHsE9Jewk7Cslz3Ay0pUQQiM2EFlWgZChBrPTYGuyyZOBaGcgSUIGKvhRAMpgVaEt5DM@lists.infradead.org X-Gm-Message-State: AOJu0YyV+s/a6SMOlUin2IW9K+vu5HF7tsRxfZtYlHUwlDckMC/9kxAP qkO/grUBZPnsUhohtaD/LEBeRAZGOwCazOkO29uT+z7D6mzeILJE X-Google-Smtp-Source: AGHT+IHGclXhRe7MiZ2gdXv83D4GWjeaFVDAh8ffxoiueuIZjAXOFvrAwN7o6rMnhdMLZv0E2Dx/ug== X-Received: by 2002:a05:6808:2f07:b0:3db:198d:97cc with SMTP id 5614622812f47-3de19d20c0emr4500013b6e.33.1724277453646; Wed, 21 Aug 2024 14:57:33 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf:81a9:2325:e0f7:7376]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225555b6sm47070b6e.17.2024.08.21.14.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 14:57:33 -0700 (PDT) From: Chris Morgan To: linux-sunxi@lists.linux.dev Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com, mripard@kernel.org, tgamblin@baylibre.com, aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de, lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, jic23@kernel.org, jonathan.cameron@huawei.com, Chris Morgan Subject: [PATCH V4 06/15] power: supply: axp20x_usb_power: add input-current-limit-microamp Date: Wed, 21 Aug 2024 16:54:47 -0500 Message-Id: <20240821215456.962564-7-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821215456.962564-1-macroalpha82@gmail.com> References: <20240821215456.962564-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_145734_454904_4D3AA35E X-CRM114-Status: GOOD ( 16.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chris Morgan Allow users to specify a maximum input current for the device. Some devices allow up to 3.25A of input current (such as the AXP717), which may be too much for some implementations. Signed-off-by: Chris Morgan --- drivers/power/supply/axp20x_usb_power.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index cd9e92f2ce71..69fbb5861934 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -80,6 +80,7 @@ struct axp20x_usb_power { struct iio_channel *vbus_v; struct iio_channel *vbus_i; struct delayed_work vbus_detect; + int max_input_cur; unsigned int old_status; unsigned int online; unsigned int num_irqs; @@ -323,6 +324,13 @@ static int axp20x_usb_power_set_input_current_limit(struct axp20x_usb_power *pow if (intval == -1) return -EINVAL; + if (power->max_input_cur && (intval > power->max_input_cur)) { + dev_warn(power->dev, + "reqested current %d clamped to max current %d\n", + intval, power->max_input_cur); + intval = power->max_input_cur; + } + /* * BC1.2 detection can cause a race condition if we try to set a current * limit while it's in progress. When it finishes it will overwrite the @@ -661,6 +669,18 @@ static int axp20x_regmap_field_alloc_optional(struct device *dev, return 0; } +/* Optionally allow users to specify a maximum charging current. */ +static void axp20x_usb_power_parse_dt(struct device *dev, + struct axp20x_usb_power *power) +{ + int ret; + + ret = device_property_read_u32(dev, "input-current-limit-microamp", + &power->max_input_cur); + if (ret) + dev_dbg(dev, "%s() no input-current-limit specified\n", __func__); +} + static int axp20x_usb_power_probe(struct platform_device *pdev) { struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); @@ -697,6 +717,8 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) if (IS_ERR(power->curr_lim_fld)) return PTR_ERR(power->curr_lim_fld); + axp20x_usb_power_parse_dt(&pdev->dev, power); + ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, axp_data->vbus_valid_bit, &power->vbus_valid_bit); From patchwork Wed Aug 21 21:54:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13772185 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4ADB2C52D7C for ; Wed, 21 Aug 2024 22:03:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RkkzIKfrsu8xLnQwZgjeVDvaKU/MUJN67PA3Rk4p0CM=; b=eGoC6DqaFxVcZxSuhGe7uCD5QL tv6vUgp8cmsLNH8ASFe8L02RU6a4yjwbpMWrK0EE6jC8nonqDQ1GcCRQaZn/xg5keAnNZg/VaA/ah JT2mpGtE5HpmgunQW4hzHEzoU0SycTBMPRd5Jh2X6h8nN49MOtWGodRtsSuzEGBvL2bL+oIiJQbSc Cgows/qbTnmdPwH9ofsHdFnxpLRPTPFKzzNLkoZ4OSaF564RtcgrSrEXmCE7ufHndyn0aS4yb2gWY 4aAub0/fNc9NJZCTCBeFahBUXVbbTccLLfNIIIExCM5Dx/jV2LkW9BTXlFxUxS901uFEj7cS3MPxv wnwZ6eWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtQ9-0000000AV5F-1pGz; Wed, 21 Aug 2024 22:03:13 +0000 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtKh-0000000AU6R-2Uqq for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 21:57:36 +0000 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3db16a98d16so88864b6e.0 for ; Wed, 21 Aug 2024 14:57:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724277454; x=1724882254; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RkkzIKfrsu8xLnQwZgjeVDvaKU/MUJN67PA3Rk4p0CM=; b=MNKjS3zh6skTTtek9c4mNnDDDXjxAbp+lEk6Ixlk2pS4MByDJT5EzMp62zv3+lJGrw 7h7Div6k45/2yxzdhCBWwKIpXqJr18YDzCT81dyrf2ancEOcdtcuX/Jv/U8/6K+8p4Og VQ4BefPHjRCrJIOnmWzBBp/8NYHqdSSIXmk0l7Fg9yo7qa658FihipnnzaOc3v8/i/B5 b0AOZeaz45yZhTlx4M4FAGIaBvu1I7MBQJBKcKBInUowpvrRj9NurxrmzOl5aF0DqA6c aUzDeUJYxQxnBQodjH8YTvjEzJQCcJfkzc36MrR2qn9Jcw3EaqXZsAfV07nD3xZnwbfo pWxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724277454; x=1724882254; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RkkzIKfrsu8xLnQwZgjeVDvaKU/MUJN67PA3Rk4p0CM=; b=kM0WEv4nn38xJ08+Uj8SzVe+c1W+JfR01GgjLiHzQ4kuX/C5skngp/H6KhmET2w1kV +0s0awSOkcP0A0L0GfmgpxVRnNgkZhV2GwdBF07lwx4SsWgzYfYUs9sBaGddqkTZ5fkC sBk5MllDnN9J5Vsrh+Y+dA3ghU3HuVhTXxGWbJbaC9feUqSdJkTQBYvAEcmFrdolAx19 k1t2lL47GTaf/g1lskLzp6RBs/cliBMg4XEVFJ3iz22F86HJOdBE39efMBUNeA2eHnUR P7GXPaNd0lj31/qfnJuPcWM3aMF2g/op9DynkG162tzwQOU2lZ/sa+gmOarPKwD4ReN0 62Pg== X-Forwarded-Encrypted: i=1; AJvYcCW4wnS47mhonidAe6qGPIAzYFdPq7aYZ31d2kNWl2XfNlhdyB2FXRmgVZR6JrzVMsRw7w5ED9nNqv+pUxyWQRPz@lists.infradead.org X-Gm-Message-State: AOJu0YwGMJY2GNILgha2bFQgNyEL1BCpFsXSRRcLSJb7D8gZ+4qp6NUg r74ANQsrMD4M+9nmZTEeMMmAMRC1naSwobM5Z8AffudsqxHd0XDW X-Google-Smtp-Source: AGHT+IGG5pB023gZP8ZguddlFNlR28q2cmj9bTwLc1Bj1tHSp3mMg1g9qpl/sTQ1MotPq+SJ7pl1cw== X-Received: by 2002:a05:6808:1796:b0:3da:aae9:7165 with SMTP id 5614622812f47-3de194f96e3mr4164334b6e.14.1724277454392; Wed, 21 Aug 2024 14:57:34 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf:81a9:2325:e0f7:7376]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225555b6sm47070b6e.17.2024.08.21.14.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 14:57:34 -0700 (PDT) From: Chris Morgan To: linux-sunxi@lists.linux.dev Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com, mripard@kernel.org, tgamblin@baylibre.com, aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de, lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, jic23@kernel.org, jonathan.cameron@huawei.com, Chris Morgan , Krzysztof Kozlowski Subject: [PATCH V4 07/15] dt-bindings: power: supply: axp20x-battery: Add monitored-battery Date: Wed, 21 Aug 2024 16:54:48 -0500 Message-Id: <20240821215456.962564-8-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821215456.962564-1-macroalpha82@gmail.com> References: <20240821215456.962564-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_145735_641890_5C44B67C X-CRM114-Status: GOOD ( 10.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chris Morgan Document the monitored-battery property, which the existing driver can use to set certain properties. Acked-by: Krzysztof Kozlowski Signed-off-by: Chris Morgan --- .../power/supply/x-powers,axp20x-battery-power-supply.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml index e0b95ecbbebd..f196bf70b248 100644 --- a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml +++ b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml @@ -28,6 +28,12 @@ properties: - const: x-powers,axp813-battery-power-supply - const: x-powers,axp813-battery-power-supply + monitored-battery: + description: + Specifies the phandle of an optional simple-battery connected to + this gauge. + $ref: /schemas/types.yaml#/definitions/phandle + required: - compatible From patchwork Wed Aug 21 21:54:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13772186 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3119EC52D7C for ; Wed, 21 Aug 2024 22:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=eGT2rYhH6YuMr14pdSYvfteEm0BRhaU6zPY4wR7HVp4=; b=Zq4KBLKUBom8t+dMNtEFPW3XC6 jZjEPgIo3mnLNgm5ZCkR960GAkuf4r+c9HpajgZLtxlQ05qZq7O2MlDMZXkrNp3aZph3CLgxHvh59 gEdMC8S6H16giEHtHanJ+spxjk/d2q3vP0YCFRqZiL9gX3tCeHhGvKlf4PCP6YJRFDQYcWx/gIjKI I5aEw/DX/OXy44yABgkIGmd+XzUSk+PQrj2bQ2LhhP5q/edTUZmA+R2cAAvqrdWIWfS38LFfz/oXG Ze2jPCuUqAtLyhkuwXK6Wlv6lAeSIZ70yhJ15kXGQLo8MVBlRHyQ4ZLULAIa2rW5QwZleTarJl/+B olv7manw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtQp-0000000AVAp-2XaO; Wed, 21 Aug 2024 22:03:55 +0000 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtKi-0000000AU6u-09Px for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 21:57:37 +0000 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-3dd16257b87so63029b6e.2 for ; Wed, 21 Aug 2024 14:57:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724277455; x=1724882255; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eGT2rYhH6YuMr14pdSYvfteEm0BRhaU6zPY4wR7HVp4=; b=RuuGv1G286dGE3uLVdVZa76FfTg2rzENtL+/trCjWcHASY1lRFWtpeZsi11wQRtWww Gddtnn8J1ivE0YLGUjaGkVjG/qjh3VMNx4SdMUpB+fJHfNV13dXi1DvEmsk8PLGWxRaC fty8IZdgBLMrz/uhwdZQBEXj+RAU9M0t/zRtn0/fxgPx814UjpJhuuc5H6iTvNG+rSum o5RU+4kqc9XBtysRIhwA838P8AzDHUz71dZfjlNhvLMnbuPDIGyfpdAn0nrMThkA7Gp0 tHHheoYvGlN1/Vs9AWIsEvxiJG3p36uBga/tCEuvMLtIIrt9OaxHIG/pU2lZp05A1Y0n +n1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724277455; x=1724882255; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eGT2rYhH6YuMr14pdSYvfteEm0BRhaU6zPY4wR7HVp4=; b=R2LO232Qd5SoXcOdjDlizsdSzjvAbDPdbpZ97Q02TmQd8AstbE5KcdqVeohpmjZ5sr wg62U40mS3Dy4ZupB2gaLZ0F0ewqlPaU1z4d7ZZmmnz7Bcj4K/T1H84RHo4D/7TG5U9r kcXdgtMfCR5O70ym4sYOo4rCynymS9ybOfC9LQurOHbd2tjzCfhd/5G25ZbeTtmUGQ36 w1H+QHCESHoiLi8ZoBCTq1lwRGkeCGMANDMZZxB5G2bhVNrSeHjDsKY7VY70WzEJrarP DRBXQuYkT3f1d+5gm0RHx3ene5Sboy6eLyzVvQwy4zDlWguwCGavshivyex1NDUEArvX kQIQ== X-Forwarded-Encrypted: i=1; AJvYcCVkW4yDaZHczfNsxyFkH7lTBHCXLH5Pb00fW7WOHb3y1+vmO6H6+Ojo0Nonr1h01scJSuz+Jm4xR6CE3pjcdBkp@lists.infradead.org X-Gm-Message-State: AOJu0YwvLQ939rCVhht3rfO1lsaX8K3V6iGpsRiDQEA7GgWahiRzK39i I6f0OATFucAyio8As0gXHAPge+2XPorTazP1MeLhoOnTI0/CxElQ X-Google-Smtp-Source: AGHT+IEmT0SJ8vvDWIKk0B/Tu72b9Who0S3hIvcO8+XPXOzOeiFwLu8KNdeN2Ow74HXfM0m1vgZkQQ== X-Received: by 2002:a05:6808:1203:b0:3d9:27fc:158f with SMTP id 5614622812f47-3de1951eed3mr4146574b6e.29.1724277455261; Wed, 21 Aug 2024 14:57:35 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf:81a9:2325:e0f7:7376]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225555b6sm47070b6e.17.2024.08.21.14.57.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 14:57:34 -0700 (PDT) From: Chris Morgan To: linux-sunxi@lists.linux.dev Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com, mripard@kernel.org, tgamblin@baylibre.com, aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de, lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, jic23@kernel.org, jonathan.cameron@huawei.com, Chris Morgan , Jonathan Cameron , Krzysztof Kozlowski Subject: [PATCH V4 08/15] dt-bindings: iio: adc: Add AXP717 compatible Date: Wed, 21 Aug 2024 16:54:49 -0500 Message-Id: <20240821215456.962564-9-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821215456.962564-1-macroalpha82@gmail.com> References: <20240821215456.962564-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_145736_083824_91389054 X-CRM114-Status: GOOD ( 10.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chris Morgan Add compatible binding for the axp717. Acked-by: Jonathan Cameron Acked-by: Krzysztof Kozlowski Signed-off-by: Chris Morgan --- .../bindings/iio/adc/x-powers,axp209-adc.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml b/Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml index d40689f233f2..1caa896fce82 100644 --- a/Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml +++ b/Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml @@ -37,6 +37,17 @@ description: | 3 | batt_dischrg_i 4 | ts_v + AXP717 + ------ + 0 | batt_v + 1 | ts_v + 2 | vbus_v + 3 | vsys_v + 4 | pmic_temp + 5 | batt_chrg_i + 6 | vmid_v + 7 | bkup_batt_v + AXP813 ------ 0 | pmic_temp @@ -52,6 +63,7 @@ properties: oneOf: - const: x-powers,axp209-adc - const: x-powers,axp221-adc + - const: x-powers,axp717-adc - const: x-powers,axp813-adc - items: From patchwork Wed Aug 21 21:54:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13772187 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B4AB6C5320E for ; Wed, 21 Aug 2024 22:04:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ys+sG5b9a6uhbl5zndW9/e6kK/Fuw6SOZtG6PQfHk44=; b=wJzXbiol8zyEbLfz5H8rxhSTry YDv2fNH2ccopR/lj8+NF5oMPGFj0vH+ekW0G7VVqAkwG3w1ZKIcuQJDMkfu2CPa/BOIfVqV5fswxQ grtnvk5L4A1svqm7vfPWk/P3SLHyuniSdxW1/+tHdmAsWcYuLdxwPcTAZ+NqLDikNN9gzlRTX9Soh PYmX5WFbEY6R6JRq2wt8aZHQMH/fovXh+h2kapDIXsBvpPESmTRoJnU1Myr1OxAs3AzL0AUASuay1 nKf4u80FkiSPFNwwAPj/kXcLVyJRoOulFkBtS6+BLRDUcvOe2FG0wB5wkw4DEOSIlIqqB3rWWzs+5 iNfmdo3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtRV-0000000AVGM-1Aje; Wed, 21 Aug 2024 22:04:37 +0000 Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtKi-0000000AU7H-3PZS for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 21:57:38 +0000 Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-3db145c8010so85816b6e.3 for ; Wed, 21 Aug 2024 14:57:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724277456; x=1724882256; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ys+sG5b9a6uhbl5zndW9/e6kK/Fuw6SOZtG6PQfHk44=; b=nghsrxMimocvBeihr1EnuQQMQXO+j47kqKHa+eMF4cGpI+GJPCBGouyhVXdvu02alw BVbth0IAlEyBBJuCNUGWA9Ztlj0brnTcyhe+ZS3qdGH57N17hd3pByJz2shT2bwKysz3 v1ZTaGYWbsD0UXO6S0QGXfTr2FL1CQVeqj3Xql8LvEME97E/pIfbDKwnzZYYyKFYxCsV XmQjFwv/BfrDijusvXYyFmgsEo66LMwZpjl2rrlGjdn3fIh9STFJXMHu2ntZWTRQkFwM 7OMIGxOKd5P7OqFf6xSTwnstGYYSPJUaiCJkfEc/x4t6w+HlARF88EjF0vkbGNJfByY2 iVkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724277456; x=1724882256; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ys+sG5b9a6uhbl5zndW9/e6kK/Fuw6SOZtG6PQfHk44=; b=JzCBY3OuC6BTN/fjooIrStA9Kc7n8pe2LLdrHoGO2woVzov1OiNlqeLHo2X3ZUxGK4 lsBjX5ZWGWKmeAx77/2CoWvnh2JYsnSCJQL1pesUsWQ3DQ/pQMnBvQONzRzjKzq/6NJm QGbHrw6Um9opYBN0Y6Q/SaCGYcMvA0Ujt6/uA/mqEG50prAwrL8t9Lerw1rtdHXkJNA7 hCyTB9Ux2vKOkLHc3XEewEnr0IXOQQRQCz7Kf82WHxXCm1F+Hpl0Zw4qIaPNKkeFtEom pNrgkTK74jl3Pv2mUfOnraL8TnbqS/ta19+Hj4osiQjnqBKwlSQ7ETieMbDs62GmUys8 z5vw== X-Forwarded-Encrypted: i=1; AJvYcCXW0WrOA29P8Fx4jS60dUu/l1yrz/+afAIe3DqvstsqZTM/lwlICENgjvi8fpNW4qPkmHsH9HrPDtEBiBuYb8Kf@lists.infradead.org X-Gm-Message-State: AOJu0YwgQngETZLPdCeEoi9WU015ieHSCF1pi9SD3LbDBFcgJDYSVXOD C6/dhUMyh8BcwZcfqKnUAlpF7Id+6Uhsgq9Z4v3AGfNOkAVRXXvV X-Google-Smtp-Source: AGHT+IGSNGiLpSDGYbeQsr9hfzMxprNvYc1rfBeR6FKiK1Zn8vEKIFHLbFvwtoPro63cqF4NO+LkPA== X-Received: by 2002:a05:6808:1211:b0:3d9:de82:f07b with SMTP id 5614622812f47-3de1951b88emr5131812b6e.28.1724277456012; Wed, 21 Aug 2024 14:57:36 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf:81a9:2325:e0f7:7376]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225555b6sm47070b6e.17.2024.08.21.14.57.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 14:57:35 -0700 (PDT) From: Chris Morgan To: linux-sunxi@lists.linux.dev Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com, mripard@kernel.org, tgamblin@baylibre.com, aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de, lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, jic23@kernel.org, jonathan.cameron@huawei.com, Chris Morgan , Krzysztof Kozlowski Subject: [PATCH V4 09/15] dt-bindings: power: supply: axp20x: Add AXP717 compatible Date: Wed, 21 Aug 2024 16:54:50 -0500 Message-Id: <20240821215456.962564-10-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821215456.962564-1-macroalpha82@gmail.com> References: <20240821215456.962564-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_145736_885626_1AE6987F X-CRM114-Status: GOOD ( 10.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chris Morgan Add support for the AXP717. It has BC 1.2 detection like the AXP813 and uses ADC channels like all other AXP devices, but otherwise is very different requiring new registers for most functions. Acked-by: Krzysztof Kozlowski Acked-by: Chen-Yu Tsai Signed-off-by: Chris Morgan --- .../supply/x-powers,axp20x-usb-power-supply.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml index ab24ebf2852f..2ec036405ae4 100644 --- a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml +++ b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml @@ -23,6 +23,7 @@ properties: - x-powers,axp202-usb-power-supply - x-powers,axp221-usb-power-supply - x-powers,axp223-usb-power-supply + - x-powers,axp717-usb-power-supply - x-powers,axp813-usb-power-supply - items: - const: x-powers,axp803-usb-power-supply @@ -75,6 +76,19 @@ allOf: input-current-limit-microamp: enum: [500000, 900000] + - if: + properties: + compatible: + contains: + enum: + - x-powers,axp717-usb-power-supply + then: + properties: + input-current-limit-microamp: + description: Maximum input current in increments of 50000 uA. + minimum: 100000 + maximum: 3250000 + - if: properties: compatible: From patchwork Wed Aug 21 21:54:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13772188 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9C2A3C52D6F for ; Wed, 21 Aug 2024 22:05:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=iBLcUKDVkwPFiYRJqjb28cNXraCEW6YLxwgaARvC0lA=; b=cj3+AEAulyWvKIRQLOtXlrwUhu 2yJOUfRopy1SgpkzHgZyDXAFkRalBhGDMZbFWiubHxsQU1vF1grmOo9zA4e6w9qWO5d/iHKPr7PpA 76eSOiP0a8hOK7KYd88x8pKpouW+tk8tds90u0R5FMZO1pajC7UVXR7icDoFxPCSiEfJbRzq/i9Ow q6tmAJ22nP/DelvG3YVC4clG8uQ20R1kW1aerah9zxg1t29lJpSIXE8FIkdUXgDD/mVPc/cg9/7WW DBhuGd8/MtXI1rDF2RbqI9IPaBK/bBdQdDPnVBwNiOenRLjxzsV1BmnaDcUjEPIUh4FPqy7+yRaI3 UIda96gA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtSB-0000000AVN5-0760; Wed, 21 Aug 2024 22:05:19 +0000 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtKk-0000000AU7h-09Hn for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 21:57:39 +0000 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3dc16d00ba6so92523b6e.0 for ; Wed, 21 Aug 2024 14:57:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724277457; x=1724882257; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iBLcUKDVkwPFiYRJqjb28cNXraCEW6YLxwgaARvC0lA=; b=Nu3/5IJYCbeSoBoyLN5Kl5KSa+J5549kgxQVQGRhhGPjAd8aIT0b3F4JSll6k12Qj8 x5YVnfL7ze9WoTsg/gzEV7ERaFz+u3Z/qNQgUkgwq/o4m51HFZm9muCV2DvTBdx/ZjRt bmDm/8hdmvgMa2zWgOiqcLVxYs0PDWXhInpWg1NGrJcTgX3Om8hRMPkv7dkuC+gZA60Q dhm5Hm/mWvnuyPHVoV8AvP7wKgmk1pHBJcHV8e523xUhlvfjbjPsdRs5PF7I1fUDtli0 I0Rur13SmFq3lICsa58F+hDf+rIe/uDKa5BRUa/HpiPXRVS/48JJ4JV2MNBI+c7+fmm6 Is/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724277457; x=1724882257; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iBLcUKDVkwPFiYRJqjb28cNXraCEW6YLxwgaARvC0lA=; b=fF7ovz5agQFsjwm2crgxccBiRmyz95UQIV51N47O2agv5tGydhgyjvp5LVdCn0160s D2fUS0I2BddejiXbStF/yu+U3DwEeW+Yv3NOhRWbjbAbfc3hbZIMDUCFSUOpNZd8au0e 4l/f0n2TYjpXRqx3B1yso5S+y/S29T+DbGTImoakfDBs6vnkVDKK99w53qnXhhu8e50I J2hp/OK+Xj08v/zJHpKHob9dOVoATl4rhIq4+f3d28WiXpvsO9sFAc3bOIavMu+F3ig3 P9wNG2tKYHNrV7YZCp5xIuA5cTaRIloBa5/6HIMaIvGgOgAYAL7crPXmCkxvCD0fr9Cz yyOQ== X-Forwarded-Encrypted: i=1; AJvYcCVLAc5UcajecYoRPs2smQUdYceJq4YEoaTlcJQZsFs08fiBXBc/oOjHihWoJnJN29YJ6cJs/v97FzOajZD3CljO@lists.infradead.org X-Gm-Message-State: AOJu0YyzZTUnSOjLXNqV1GDOnWIHZD0HjYBA92+S3Mp/sLlyVK5E7eyC XmxDfiyj3EzviHPIc7k4lJsEL//adrlTC1ygsNW95xuGDiAog8kH X-Google-Smtp-Source: AGHT+IFBH/Id49Is4rvox6d7qJv1gU0KdeZpKbRB9tXQkrhso5+9Wd6ArhEi7XMb6kv3+haBhqqwxQ== X-Received: by 2002:a05:6808:654b:b0:3da:ab89:a808 with SMTP id 5614622812f47-3de19510ef5mr3509342b6e.20.1724277456885; Wed, 21 Aug 2024 14:57:36 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf:81a9:2325:e0f7:7376]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225555b6sm47070b6e.17.2024.08.21.14.57.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 14:57:36 -0700 (PDT) From: Chris Morgan To: linux-sunxi@lists.linux.dev Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com, mripard@kernel.org, tgamblin@baylibre.com, aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de, lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, jic23@kernel.org, jonathan.cameron@huawei.com, Chris Morgan , Krzysztof Kozlowski Subject: [PATCH V4 10/15] dt-bindings: power: supply: axp20x: Add AXP717 compatible Date: Wed, 21 Aug 2024 16:54:51 -0500 Message-Id: <20240821215456.962564-11-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821215456.962564-1-macroalpha82@gmail.com> References: <20240821215456.962564-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_145738_111802_4C5B471C X-CRM114-Status: UNSURE ( 9.90 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chris Morgan Add binding information for AXP717. Acked-by: Krzysztof Kozlowski Signed-off-by: Chris Morgan --- .../power/supply/x-powers,axp20x-battery-power-supply.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml index f196bf70b248..5ccd375eb294 100644 --- a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml +++ b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml @@ -23,6 +23,7 @@ properties: - const: x-powers,axp202-battery-power-supply - const: x-powers,axp209-battery-power-supply - const: x-powers,axp221-battery-power-supply + - const: x-powers,axp717-battery-power-supply - items: - const: x-powers,axp803-battery-power-supply - const: x-powers,axp813-battery-power-supply From patchwork Wed Aug 21 21:54:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13772189 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1645AC52D6F for ; Wed, 21 Aug 2024 22:06:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8/L+1F4zI2xR0RRUKLsollddkiZWe3KRdF8cSYPvQkI=; b=d2HkE//xzA0G5mINezEJT5GVZe LC89EHc9pVpBKN5WB1mrAoyJKTG+pJDOUcdwoGaJStR5q9U7u12ujgbXSEHcXVn+9bcc/cmXN7ere 0Zy2Qzpv6RQHvjFkmjKJkUExg1tgQhc19cvxn7a3NB1aRxo0jKZn6GuxZDGpx6Oggm40KLjHo1wBM NZWn7vLjJHo6VA2U9mLPxrKCcBDeuVJGSTRwEHaDOoEdQLlUeUv9w9s+/6qYzkPK4VD6kpA3oBa4u EiXrYtPbUe/jJMyidBMQgcTpUnds9mLGAUrk1qeYPY2K6fKUi3ipu0XJ9fAHiUIGyyT0I7+44n9Ne W8APVqxw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtSr-0000000AVTF-3Rbo; Wed, 21 Aug 2024 22:06:01 +0000 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtKk-0000000AU88-3hBg for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 21:57:40 +0000 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3db12a2f530so92220b6e.1 for ; Wed, 21 Aug 2024 14:57:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724277458; x=1724882258; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8/L+1F4zI2xR0RRUKLsollddkiZWe3KRdF8cSYPvQkI=; b=ey6t/NiWYFWziulUHegLnExxecJX9J1EFaa1xsNVC/p3g0cByLcvXvfIDvRxYXv4Qx Q2h6/AZMA4XBrxN0S7/fYEMTglSq4W6RFRjCK8pjA/SRMZQZ9Q6z6DgoKYW3sTo1H5zR khSYZi4bXcUG390PBMEcAfgPgYT3wMQyCe6Pb6FXNYHij/tPCyunBV4Eu+hT6MFwrhIX RaLzkAZciWBCre47AmleMqiShRw81bsbPLHAiYQuTX73Ux+h600a5D1ArnMYdbRwEcP2 ZqQ2jMOmD64h3y2k0FZkA3kEKeUk4z4lT17X5m4cblxF7R9aDocdf+TA+W89jXOSa6C8 qIag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724277458; x=1724882258; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8/L+1F4zI2xR0RRUKLsollddkiZWe3KRdF8cSYPvQkI=; b=ugg3IWGrd8y0YiRd9hYR5lOmW7KzmE0M1MFklpChFsYp03MHqA7SE2SlquWdInm+Bl UWqt84l1M6y6MzJZ/jSJoXO0t2jdrcss92oSBUhFZrJB+0meitIaM9vNERituiiHa/ho ntltWbjk4/cJ8tO3/QibShkFjjWRP4E0dFktgrDlnazMTKeOcObcW7gqOEXpYb1ntfVS AVgcKkVkzTr+qIY6pl8qjbiyItf2EfmN+adPbm3ilsQpf7lnQHVKPjLq5ytmKH7E5cLh eHEPYL60OVYeiSwzyEYon+/fLNFFWhL5IwG9rE4Ul/YF81afGVgSLRDFSk3IufIH6B00 Sr4w== X-Forwarded-Encrypted: i=1; AJvYcCW9emI9LP0u9KplwqNGiJzc6eGq2Y7S6MDuVt40ogLV6grXinCPQh+bpKKMlvQc38n2w+bCpfhy4UA0De+Y5cOt@lists.infradead.org X-Gm-Message-State: AOJu0YwDGKqjQOgaikdlzQQAqoGR+1XA2sg5GZiI4nWopzDnMjRNA/Ar x8808NaBhj99wHJ+2+ma5mQ4pkB4VK8bkzPRNgwZgjzyzCsbnaWd X-Google-Smtp-Source: AGHT+IGhrFvuL7dyQu3IcgXKKeTpaz1U3EOzYER3pTHvrhHmhzWAxc9pkysLN99haFIpxfz1sgm/aA== X-Received: by 2002:a05:6808:22a6:b0:3d9:24f8:7dd2 with SMTP id 5614622812f47-3de19c75b27mr3972560b6e.6.1724277457716; Wed, 21 Aug 2024 14:57:37 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf:81a9:2325:e0f7:7376]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225555b6sm47070b6e.17.2024.08.21.14.57.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 14:57:37 -0700 (PDT) From: Chris Morgan To: linux-sunxi@lists.linux.dev Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com, mripard@kernel.org, tgamblin@baylibre.com, aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de, lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, jic23@kernel.org, jonathan.cameron@huawei.com, Chris Morgan Subject: [PATCH V4 11/15] mfd: axp20x: Add ADC, BAT, and USB cells for AXP717 Date: Wed, 21 Aug 2024 16:54:52 -0500 Message-Id: <20240821215456.962564-12-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821215456.962564-1-macroalpha82@gmail.com> References: <20240821215456.962564-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_145738_945732_47EA7D17 X-CRM114-Status: GOOD ( 15.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chris Morgan Add support for the AXP717 PMIC to utilize the ADC (for reading voltage, current, and temperature information from the PMIC) as well as the USB charger and battery. Signed-off-by: Chris Morgan --- drivers/mfd/axp20x.c | 25 ++++++++++++++++++++++++- include/linux/mfd/axp20x.h | 26 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c index dacd3c96c9f5..4051551757f2 100644 --- a/drivers/mfd/axp20x.c +++ b/drivers/mfd/axp20x.c @@ -209,13 +209,23 @@ static const struct regmap_access_table axp313a_volatile_table = { }; static const struct regmap_range axp717_writeable_ranges[] = { + regmap_reg_range(AXP717_PMU_FAULT, AXP717_MODULE_EN_CONTROL_1), + regmap_reg_range(AXP717_MIN_SYS_V_CONTROL, AXP717_BOOST_CONTROL), + regmap_reg_range(AXP717_VSYS_V_POWEROFF, AXP717_VSYS_V_POWEROFF), regmap_reg_range(AXP717_IRQ0_EN, AXP717_IRQ4_EN), regmap_reg_range(AXP717_IRQ0_STATE, AXP717_IRQ4_STATE), + regmap_reg_range(AXP717_ICC_CHG_SET, AXP717_CV_CHG_SET), regmap_reg_range(AXP717_DCDC_OUTPUT_CONTROL, AXP717_CPUSLDO_CONTROL), + regmap_reg_range(AXP717_ADC_CH_EN_CONTROL, AXP717_ADC_CH_EN_CONTROL), + regmap_reg_range(AXP717_ADC_DATA_SEL, AXP717_ADC_DATA_SEL), }; static const struct regmap_range axp717_volatile_ranges[] = { + regmap_reg_range(AXP717_ON_INDICATE, AXP717_PMU_FAULT), regmap_reg_range(AXP717_IRQ0_STATE, AXP717_IRQ4_STATE), + regmap_reg_range(AXP717_BATT_PERCENT_DATA, AXP717_BATT_PERCENT_DATA), + regmap_reg_range(AXP717_BATT_V_H, AXP717_BATT_CHRG_I_L), + regmap_reg_range(AXP717_ADC_DATA_H, AXP717_ADC_DATA_L), }; static const struct regmap_access_table axp717_writeable_table = { @@ -308,6 +318,12 @@ static const struct resource axp22x_usb_power_supply_resources[] = { DEFINE_RES_IRQ_NAMED(AXP22X_IRQ_VBUS_REMOVAL, "VBUS_REMOVAL"), }; +static const struct resource axp717_usb_power_supply_resources[] = { + DEFINE_RES_IRQ_NAMED(AXP717_IRQ_VBUS_OVER_V, "VBUS_OVER_V"), + DEFINE_RES_IRQ_NAMED(AXP717_IRQ_VBUS_PLUGIN, "VBUS_PLUGIN"), + DEFINE_RES_IRQ_NAMED(AXP717_IRQ_VBUS_REMOVAL, "VBUS_REMOVAL"), +}; + /* AXP803 and AXP813/AXP818 share the same interrupts */ static const struct resource axp803_usb_power_supply_resources[] = { DEFINE_RES_IRQ_NAMED(AXP803_IRQ_VBUS_PLUGIN, "VBUS_PLUGIN"), @@ -422,7 +438,7 @@ static const struct regmap_config axp717_regmap_config = { .val_bits = 8, .wr_table = &axp717_writeable_table, .volatile_table = &axp717_volatile_table, - .max_register = AXP717_CPUSLDO_CONTROL, + .max_register = AXP717_ADC_DATA_L, .cache_type = REGCACHE_MAPLE, }; @@ -1024,6 +1040,13 @@ static struct mfd_cell axp313a_cells[] = { static struct mfd_cell axp717_cells[] = { MFD_CELL_NAME("axp20x-regulator"), MFD_CELL_RES("axp20x-pek", axp717_pek_resources), + MFD_CELL_OF("axp717-adc", + NULL, NULL, 0, 0, "x-powers,axp717-adc"), + MFD_CELL_OF("axp20x-usb-power-supply", + axp717_usb_power_supply_resources, NULL, 0, 0, + "x-powers,axp717-usb-power-supply"), + MFD_CELL_OF("axp20x-battery-power-supply", + NULL, NULL, 0, 0, "x-powers,axp717-battery-power-supply"), }; static const struct resource axp288_adc_resources[] = { diff --git a/include/linux/mfd/axp20x.h b/include/linux/mfd/axp20x.h index 8c0a33a2e9ce..9b7ef473adcb 100644 --- a/include/linux/mfd/axp20x.h +++ b/include/linux/mfd/axp20x.h @@ -115,6 +115,16 @@ enum axp20x_variants { #define AXP313A_IRQ_STATE 0x21 #define AXP717_ON_INDICATE 0x00 +#define AXP717_PMU_STATUS_2 0x01 +#define AXP717_BC_DETECT 0x05 +#define AXP717_PMU_FAULT 0x08 +#define AXP717_MODULE_EN_CONTROL_1 0x0b +#define AXP717_MIN_SYS_V_CONTROL 0x15 +#define AXP717_INPUT_VOL_LIMIT_CTRL 0x16 +#define AXP717_INPUT_CUR_LIMIT_CTRL 0x17 +#define AXP717_MODULE_EN_CONTROL_2 0x19 +#define AXP717_BOOST_CONTROL 0x1e +#define AXP717_VSYS_V_POWEROFF 0x24 #define AXP717_IRQ0_EN 0x40 #define AXP717_IRQ1_EN 0x41 #define AXP717_IRQ2_EN 0x42 @@ -125,6 +135,9 @@ enum axp20x_variants { #define AXP717_IRQ2_STATE 0x4a #define AXP717_IRQ3_STATE 0x4b #define AXP717_IRQ4_STATE 0x4c +#define AXP717_ICC_CHG_SET 0x62 +#define AXP717_ITERM_CHG_SET 0x63 +#define AXP717_CV_CHG_SET 0x64 #define AXP717_DCDC_OUTPUT_CONTROL 0x80 #define AXP717_DCDC1_CONTROL 0x83 #define AXP717_DCDC2_CONTROL 0x84 @@ -145,6 +158,19 @@ enum axp20x_variants { #define AXP717_CLDO3_CONTROL 0x9d #define AXP717_CLDO4_CONTROL 0x9e #define AXP717_CPUSLDO_CONTROL 0x9f +#define AXP717_BATT_PERCENT_DATA 0xa4 +#define AXP717_ADC_CH_EN_CONTROL 0xc0 +#define AXP717_BATT_V_H 0xc4 +#define AXP717_BATT_V_L 0xc5 +#define AXP717_VBUS_V_H 0xc6 +#define AXP717_VBUS_V_L 0xc7 +#define AXP717_VSYS_V_H 0xc8 +#define AXP717_VSYS_V_L 0xc9 +#define AXP717_BATT_CHRG_I_H 0xca +#define AXP717_BATT_CHRG_I_L 0xcb +#define AXP717_ADC_DATA_SEL 0xcd +#define AXP717_ADC_DATA_H 0xce +#define AXP717_ADC_DATA_L 0xcf #define AXP806_STARTUP_SRC 0x00 #define AXP806_CHIP_ID 0x03 From patchwork Wed Aug 21 21:54:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13772190 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB99FC52D7C for ; Wed, 21 Aug 2024 22:06:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1BG4Yu5v0RvMg9BKBblbkcV218rJFGY03uUE/RovoZ8=; b=YnSk3kgQVtHYI66pMNHPuLyku2 6wO1I4rO/o1FW5UgqwxXmeCL8xcLUlCdYYdE4uXdgGImt3hPmcWkT0Gvej3g/qdkGNAlIRAoAO8aP hrXDHBaEdSd68Ue7o7x1HKeSHnogAxGLc4giCfddUP3utGqG8uc9sbgquuLQwIrolazXEtB7dCHF6 K7DF/UsaJiQbdBIEW52jrRLRoTNHPB7pgtvQh0I2eh5g8cxyPP3+/e1+8t18R3W1q8rZFoiU4fu5G IIVd7jm5OAdlXKDxabmQVw9AAG4VQQnvNkhZrUNkw62CIA4G+yH32HIZAvdet3ux8uj3tU5li3pvP yYGdfs5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtTX-0000000AVZw-3NOb; Wed, 21 Aug 2024 22:06:43 +0000 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtKl-0000000AU8K-2Kfu for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 21:57:40 +0000 Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3db1657c0fdso86334b6e.1 for ; Wed, 21 Aug 2024 14:57:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724277458; x=1724882258; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1BG4Yu5v0RvMg9BKBblbkcV218rJFGY03uUE/RovoZ8=; b=CD998WyaRumKZCKHMxM4yESkCsOn9YwC/20eMZ0BDNPyWdPJ8xMbVSsVtnzkSOeOWH rpdWBpzjtYG+F3UgTCxmrg+BRvvu8ZdTlwjYeWM6AneeSqGKKZSoA6FXaLMhMdRT4OFs 12+0HZHuleP7kNPAU26hrGaXRext8hPE7X9J0Cul0jzwVLvPZUJUxBsuDFGWtLZeTP+1 HLLT/pzVpbdj+UBDGuYpPZXHh85xAUEOA9L6fq2yeIYdtswWi6eSe0klLxJZVjtAWt5O mvpY9UWBFhNEJmvBC8TbcdXCPijenl2DDkkCFHl/SFmEk0EFa2/0PvrTT1fzHVSmmdop +CLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724277458; x=1724882258; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1BG4Yu5v0RvMg9BKBblbkcV218rJFGY03uUE/RovoZ8=; b=jeSUJA45JLIG35dNV2vQ7gBjFb1NQXXd5uFbUjJWPGFUzrWDeXcUoe0gFlCyrMwaM6 G9OD5b7vJM9pSXpRJdY2cp0opBARvRfiz9LpTrssbp43jYmtQpQsha6oBqTgbhBR3jc4 4IfjLxwcZ9/eom0bucAxhK1XJ1HJM/Utk1vprSucu0UsNdq+LjYoKz2dTJMPqqFSmuw3 F7CBcmkema7kdKBxzpLxsebZn/yl2C1TxunKKOFagE3Um9la4SwXGervyNjfppR69rY8 sm8tsWGP3hxz0SlYaZqJEBEVSKXb/V8VAHvPDwrEMcbSlfIKb4hrJeAO9xGKUU1GBxmF 8WXg== X-Forwarded-Encrypted: i=1; AJvYcCVYWVoG4lz0q0nkdTwtIz+aQAs9v0K8YR+jLOSkfL3S4E2u1CuJncN9ITKlrMbMojuEbxL7JIfre5NxdoGYxjxK@lists.infradead.org X-Gm-Message-State: AOJu0YxdnlZDMYPQk8wJ1PPZ8oW9Gm0J3LOou/bZtKrhYRYe2uAg7tv3 Zymrp+8Olph3s6bisAcTAqb68g6a+HWMMT8T+1Tyf3pze6U5WpZj X-Google-Smtp-Source: AGHT+IGGM/dt7n0rISg0md3pWPxlPDaO7cmVNBpLwos7ZMstoxefre8iJMlXeJySIXx9UESf0y4NPg== X-Received: by 2002:a05:6808:1402:b0:3da:e246:36f9 with SMTP id 5614622812f47-3de19d18709mr4637314b6e.31.1724277458462; Wed, 21 Aug 2024 14:57:38 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf:81a9:2325:e0f7:7376]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225555b6sm47070b6e.17.2024.08.21.14.57.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 14:57:38 -0700 (PDT) From: Chris Morgan To: linux-sunxi@lists.linux.dev Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com, mripard@kernel.org, tgamblin@baylibre.com, aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de, lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, jic23@kernel.org, jonathan.cameron@huawei.com, Chris Morgan , Jonathan Cameron Subject: [PATCH V4 12/15] iio: adc: axp20x_adc: add support for AXP717 ADC Date: Wed, 21 Aug 2024 16:54:53 -0500 Message-Id: <20240821215456.962564-13-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821215456.962564-1-macroalpha82@gmail.com> References: <20240821215456.962564-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_145739_615435_CC9703F8 X-CRM114-Status: GOOD ( 22.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chris Morgan Add support for the AXP717 ADC. The AXP717 differs from other ADCs in this series by utilizing a 14 bit ADC for all channels (a full 16 bits with the first 2 digits reserved). It also differs by lacking a battery discharge current channel. Note that while the current charge channel itself is included in this driver for the AXP717 and listed in the datasheet, no scale or offset was given for this channel. For now no scale or offset is provided in this driver. Acked-by: Jonathan Cameron Signed-off-by: Chris Morgan --- drivers/iio/adc/axp20x_adc.c | 160 +++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/drivers/iio/adc/axp20x_adc.c b/drivers/iio/adc/axp20x_adc.c index 368ba6ee7a80..d43c8d124a0c 100644 --- a/drivers/iio/adc/axp20x_adc.c +++ b/drivers/iio/adc/axp20x_adc.c @@ -5,6 +5,7 @@ * Quentin Schulz */ +#include #include #include #include @@ -30,6 +31,8 @@ #define AXP22X_ADC_EN1_MASK (GENMASK(7, 5) | BIT(0)) +#define AXP717_ADC_EN1_MASK GENMASK(7, 0) + #define AXP192_GPIO30_IN_RANGE_GPIO0 BIT(0) #define AXP192_GPIO30_IN_RANGE_GPIO1 BIT(1) #define AXP192_GPIO30_IN_RANGE_GPIO2 BIT(2) @@ -43,6 +46,13 @@ #define AXP22X_ADC_RATE_HZ(x) ((ilog2((x) / 100) << 6) & AXP20X_ADC_RATE_MASK) +#define AXP717_ADC_DATA_TS 0x00 +#define AXP717_ADC_DATA_TEMP 0x01 +#define AXP717_ADC_DATA_VMID 0x02 +#define AXP717_ADC_DATA_BKUP_BATT 0x03 + +#define AXP717_ADC_DATA_MASK GENMASK(13, 0) + #define AXP813_V_I_ADC_RATE_MASK GENMASK(5, 4) #define AXP813_ADC_RATE_MASK (AXP20X_ADC_RATE_MASK | AXP813_V_I_ADC_RATE_MASK) #define AXP813_TS_GPIO0_ADC_RATE_HZ(x) AXP20X_ADC_RATE_HZ(x) @@ -125,6 +135,20 @@ enum axp22x_adc_channel_i { AXP22X_BATT_DISCHRG_I, }; +enum axp717_adc_channel_v { + AXP717_BATT_V = 0, + AXP717_TS_IN, + AXP717_VBUS_V, + AXP717_VSYS_V, + AXP717_DIE_TEMP_V, + AXP717_VMID_V = 6, + AXP717_BKUP_BATT_V, +}; + +enum axp717_adc_channel_i { + AXP717_BATT_CHRG_I = 5, +}; + enum axp813_adc_channel_v { AXP813_TS_IN = 0, AXP813_GPIO0_V, @@ -179,6 +203,22 @@ static struct iio_map axp22x_maps[] = { }, { /* sentinel */ } }; +static struct iio_map axp717_maps[] = { + { + .consumer_dev_name = "axp20x-usb-power-supply", + .consumer_channel = "vbus_v", + .adc_channel_label = "vbus_v", + }, { + .consumer_dev_name = "axp20x-battery-power-supply", + .consumer_channel = "batt_v", + .adc_channel_label = "batt_v", + }, { + .consumer_dev_name = "axp20x-battery-power-supply", + .consumer_channel = "batt_chrg_i", + .adc_channel_label = "batt_chrg_i", + }, +}; + /* * Channels are mapped by physical system. Their channels share the same index. * i.e. acin_i is in_current0_raw and acin_v is in_voltage0_raw. @@ -274,6 +314,29 @@ static const struct iio_chan_spec axp22x_adc_channels[] = { AXP22X_TS_ADC_H), }; +/* + * Scale and offset is unknown for temp, ts, batt_chrg_i, vmid_v, and + * bkup_batt_v channels. Leaving scale and offset undefined for now. + */ +static const struct iio_chan_spec axp717_adc_channels[] = { + AXP20X_ADC_CHANNEL(AXP717_BATT_V, "batt_v", IIO_VOLTAGE, + AXP717_BATT_V_H), + AXP20X_ADC_CHANNEL(AXP717_TS_IN, "ts_v", IIO_VOLTAGE, + AXP717_ADC_DATA_H), + AXP20X_ADC_CHANNEL(AXP717_VBUS_V, "vbus_v", IIO_VOLTAGE, + AXP717_VBUS_V_H), + AXP20X_ADC_CHANNEL(AXP717_VSYS_V, "vsys_v", IIO_VOLTAGE, + AXP717_VSYS_V_H), + AXP20X_ADC_CHANNEL(AXP717_DIE_TEMP_V, "pmic_temp", IIO_TEMP, + AXP717_ADC_DATA_H), + AXP20X_ADC_CHANNEL(AXP717_BATT_CHRG_I, "batt_chrg_i", IIO_CURRENT, + AXP717_BATT_CHRG_I_H), + AXP20X_ADC_CHANNEL(AXP717_VMID_V, "vmid_v", IIO_VOLTAGE, + AXP717_ADC_DATA_H), + AXP20X_ADC_CHANNEL(AXP717_BKUP_BATT_V, "bkup_batt_v", IIO_VOLTAGE, + AXP717_ADC_DATA_H), +}; + static const struct iio_chan_spec axp813_adc_channels[] = { { .type = IIO_TEMP, @@ -354,6 +417,51 @@ static int axp22x_adc_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; } +static int axp717_adc_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val) +{ + struct axp20x_adc_iio *info = iio_priv(indio_dev); + u8 bulk_reg[2]; + int ret; + + /* + * A generic "ADC data" channel is used for TS, tdie, vmid, + * and vbackup. This channel must both first be enabled and + * also selected before it can be read. + */ + switch (chan->channel) { + case AXP717_TS_IN: + regmap_write(info->regmap, AXP717_ADC_DATA_SEL, + AXP717_ADC_DATA_TS); + break; + case AXP717_DIE_TEMP_V: + regmap_write(info->regmap, AXP717_ADC_DATA_SEL, + AXP717_ADC_DATA_TEMP); + break; + case AXP717_VMID_V: + regmap_write(info->regmap, AXP717_ADC_DATA_SEL, + AXP717_ADC_DATA_VMID); + break; + case AXP717_BKUP_BATT_V: + regmap_write(info->regmap, AXP717_ADC_DATA_SEL, + AXP717_ADC_DATA_BKUP_BATT); + break; + default: + break; + } + + /* + * All channels are 14 bits, with the first 2 bits on the high + * register reserved and the remaining bits as the ADC value. + */ + ret = regmap_bulk_read(info->regmap, chan->address, bulk_reg, 2); + if (ret < 0) + return ret; + + *val = FIELD_GET(AXP717_ADC_DATA_MASK, get_unaligned_be16(bulk_reg)); + return IIO_VAL_INT; +} + static int axp813_adc_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val) { @@ -571,6 +679,27 @@ static int axp22x_adc_scale(struct iio_chan_spec const *chan, int *val, } } +static int axp717_adc_scale(struct iio_chan_spec const *chan, int *val, + int *val2) +{ + switch (chan->type) { + case IIO_VOLTAGE: + *val = 1; + return IIO_VAL_INT; + + case IIO_CURRENT: + *val = 1; + return IIO_VAL_INT; + + case IIO_TEMP: + *val = 100; + return IIO_VAL_INT; + + default: + return -EINVAL; + } +} + static int axp813_adc_scale(struct iio_chan_spec const *chan, int *val, int *val2) { @@ -746,6 +875,22 @@ static int axp22x_read_raw(struct iio_dev *indio_dev, } } +static int axp717_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, + int *val2, long mask) +{ + switch (mask) { + case IIO_CHAN_INFO_SCALE: + return axp717_adc_scale(chan, val, val2); + + case IIO_CHAN_INFO_RAW: + return axp717_adc_raw(indio_dev, chan, val); + + default: + return -EINVAL; + } +} + static int axp813_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) @@ -860,6 +1005,10 @@ static const struct iio_info axp22x_adc_iio_info = { .read_raw = axp22x_read_raw, }; +static const struct iio_info axp717_adc_iio_info = { + .read_raw = axp717_read_raw, +}; + static const struct iio_info axp813_adc_iio_info = { .read_raw = axp813_read_raw, }; @@ -930,6 +1079,15 @@ static const struct axp_data axp22x_data = { .maps = axp22x_maps, }; +static const struct axp_data axp717_data = { + .iio_info = &axp717_adc_iio_info, + .num_channels = ARRAY_SIZE(axp717_adc_channels), + .channels = axp717_adc_channels, + .adc_en1 = AXP717_ADC_CH_EN_CONTROL, + .adc_en1_mask = AXP717_ADC_EN1_MASK, + .maps = axp717_maps, +}; + static const struct axp_data axp813_data = { .iio_info = &axp813_adc_iio_info, .num_channels = ARRAY_SIZE(axp813_adc_channels), @@ -944,6 +1102,7 @@ static const struct of_device_id axp20x_adc_of_match[] = { { .compatible = "x-powers,axp192-adc", .data = (void *)&axp192_data, }, { .compatible = "x-powers,axp209-adc", .data = (void *)&axp20x_data, }, { .compatible = "x-powers,axp221-adc", .data = (void *)&axp22x_data, }, + { .compatible = "x-powers,axp717-adc", .data = (void *)&axp717_data, }, { .compatible = "x-powers,axp813-adc", .data = (void *)&axp813_data, }, { /* sentinel */ } }; @@ -953,6 +1112,7 @@ static const struct platform_device_id axp20x_adc_id_match[] = { { .name = "axp192-adc", .driver_data = (kernel_ulong_t)&axp192_data, }, { .name = "axp20x-adc", .driver_data = (kernel_ulong_t)&axp20x_data, }, { .name = "axp22x-adc", .driver_data = (kernel_ulong_t)&axp22x_data, }, + { .name = "axp717-adc", .driver_data = (kernel_ulong_t)&axp717_data, }, { .name = "axp813-adc", .driver_data = (kernel_ulong_t)&axp813_data, }, { /* sentinel */ }, }; From patchwork Wed Aug 21 21:54:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13772191 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8AB2DC52D7C for ; Wed, 21 Aug 2024 22:07:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wzwbUBXpQ31q7HNv2dH+jmh+P3HKqC3um14cKU6HarE=; b=XVHCp2USnxpALU1+3Uj2xs6TDn emrOV8V1wjtPYhYcKBJKN0wTkF90UucuQBcz5F8/coIPKBGgiTDfjAD5TpEA8YCDHP7D6GJu4SKe/ rOydkZJyvcd+0bZvAS6YXmiuQ5sNu1ID2z2EN3p+3/mahHmYMz80bkNBy+80KXe6p0sJ3MXL8oeAu /Ij7VnvvZ5yke+MtIy2g7ii2Vy8JnhbZW8lPz4XJ0yZMLLM7kky/2csggalsqTRtGOo1H7A456Z/g Xd7JWJc/Zy6zRBwkxc/fcXvAbs9CyKgwt2djRma6pyvAqGVJwW/bLW0KYblBtPyyn5z2PHX7racbZ /piatDpw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtUD-0000000AVg8-1mmD; Wed, 21 Aug 2024 22:07:25 +0000 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtKm-0000000AU8s-0OJq for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 21:57:41 +0000 Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3db23a60850so87497b6e.0 for ; Wed, 21 Aug 2024 14:57:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724277459; x=1724882259; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wzwbUBXpQ31q7HNv2dH+jmh+P3HKqC3um14cKU6HarE=; b=fXFDR+fXzcuFYuJ+hrIDqcvDGmJakK18rW20AWGf06skzliJougLmq6js9u8PPm6j9 /u9qc7jamnumdNTXnr9TradGrpSBB2GZ/AvU80XXhMk4Z1KeKG8NIRcxplEeg7zCQtSA 6tp1lA7pygsO2EUpAsD9e9hxrv6MDlYhBxm764OiZbQLl4OIRsUEtc4WR4h5V77LhwYW w0OBNbgp9/b+eObJ2pmaPQthtFNgTnOG5miVh00CNeIW1/NbIGAe+Mx1TMYIGlX1xOJ4 s9hZsjM3M1x2KVQhc2WVTHMf6rzTp6QbDKKYnqLqV8LvrT0sZgZcP4olUjAR2zjEeWgG 7DmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724277459; x=1724882259; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wzwbUBXpQ31q7HNv2dH+jmh+P3HKqC3um14cKU6HarE=; b=PsF/aC2QcmIUSOqy7XLxve2T4Px/Jj0UQOKCNw7nPSKBxiUvoYdKNG+LkBoRlbJ/wH BoaIa15SuiRC1Sb9mBszinOJ23Us4sXho8szF3sE7ZGWYnLHpXVVL5qC0uLaBr3xCYle Ci+i6ss8MKleI8rICfQMqQLW4or/oJMgjjLciDbuykQtPMgst5DxB4/cEJqi3L+Sumkd 5MZ3h405gITFs0awunEbsHmPNcSLt5wq51q644U/bRcUAhMtmxayVDtpIjPqMzI/7UBb l9kOifHbqTjcPaWQXAkrzlBiTDxlmtvYL1HbqJgSrPgYG+/ieAPDYVOBhlzFtZ30oMcC vyYg== X-Forwarded-Encrypted: i=1; AJvYcCUjiuWOfyu5swMV9bVksdsmo7SCvi7PA1uybwk+4GKdQLInhDLu1hKiUG+A93UZ9CEm3gUNO1Lo2jx5tnrfUGBz@lists.infradead.org X-Gm-Message-State: AOJu0YyOHEi9H4cP0sK7D0ceJUyn9sr2Tc6RUWNThEXD8kXvCtyi2dV2 lIDwCVrRjYdHYEz301QOK1JMFI7wN/ZMuCi8P4mYwRIl44MjPJ90 X-Google-Smtp-Source: AGHT+IEmeHydqhJY3UklnOsjpdPCZB7Pp0GjV6AKzGOzJR5In+g2CVsY04kam57ncntLdg6QcPqDmQ== X-Received: by 2002:a05:6808:10cc:b0:3dd:2b80:23bf with SMTP id 5614622812f47-3de19c75beamr3840823b6e.9.1724277459240; Wed, 21 Aug 2024 14:57:39 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf:81a9:2325:e0f7:7376]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225555b6sm47070b6e.17.2024.08.21.14.57.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 14:57:38 -0700 (PDT) From: Chris Morgan To: linux-sunxi@lists.linux.dev Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com, mripard@kernel.org, tgamblin@baylibre.com, aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de, lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, jic23@kernel.org, jonathan.cameron@huawei.com, Chris Morgan , Philippe Simons Subject: [PATCH V4 13/15] power: supply: axp20x_usb_power: Add support for AXP717 Date: Wed, 21 Aug 2024 16:54:54 -0500 Message-Id: <20240821215456.962564-14-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821215456.962564-1-macroalpha82@gmail.com> References: <20240821215456.962564-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_145740_163992_E56768D7 X-CRM114-Status: GOOD ( 22.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chris Morgan Add support for the AXP717 PMIC. The AXP717 PMIC allows for detection of USB type like the AXP813, but has little in common otherwise with the other AXP PMICs. The USB charger is able to provide between 100000uA and 3250000uA of power, and can measure the VBUS input in mV with up to 14 bits of precision. Tested-by: Philippe Simons Signed-off-by: Chris Morgan --- drivers/power/supply/axp20x_usb_power.c | 244 ++++++++++++++++++++++++ 1 file changed, 244 insertions(+) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 69fbb5861934..41426fca8cfc 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -30,8 +30,13 @@ #define AXP20X_PWR_STATUS_VBUS_PRESENT BIT(5) #define AXP20X_PWR_STATUS_VBUS_USED BIT(4) +#define AXP717_PWR_STATUS_VBUS_GOOD BIT(5) + #define AXP20X_USB_STATUS_VBUS_VALID BIT(2) +#define AXP717_PMU_FAULT_VBUS BIT(5) +#define AXP717_PMU_FAULT_VSYS BIT(3) + #define AXP20X_VBUS_VHOLD_uV(b) (4000000 + (((b) >> 3) & 7) * 100000) #define AXP20X_VBUS_VHOLD_MASK GENMASK(5, 3) #define AXP20X_VBUS_VHOLD_OFFSET 3 @@ -39,6 +44,12 @@ #define AXP20X_ADC_EN1_VBUS_CURR BIT(2) #define AXP20X_ADC_EN1_VBUS_VOLT BIT(3) +#define AXP717_INPUT_VOL_LIMIT_MASK GENMASK(3, 0) +#define AXP717_INPUT_CUR_LIMIT_MASK GENMASK(5, 0) +#define AXP717_ADC_DATA_MASK GENMASK(14, 0) + +#define AXP717_ADC_EN_VBUS_VOLT BIT(2) + /* * Note do not raise the debounce time, we must report Vusb high within * 100ms otherwise we get Vbus errors in musb. @@ -143,6 +154,24 @@ static void axp20x_usb_power_poll_vbus(struct work_struct *work) mod_delayed_work(system_power_efficient_wq, &power->vbus_detect, DEBOUNCE_TIME); } +static void axp717_usb_power_poll_vbus(struct work_struct *work) +{ + struct axp20x_usb_power *power = + container_of(work, struct axp20x_usb_power, vbus_detect.work); + unsigned int val; + int ret; + + ret = regmap_read(power->regmap, AXP717_ON_INDICATE, &val); + if (ret) + return; + + val &= AXP717_PWR_STATUS_VBUS_GOOD; + if (val != power->old_status) + power_supply_changed(power->supply); + + power->old_status = val; +} + static int axp20x_get_usb_type(struct axp20x_usb_power *power, union power_supply_propval *val) { @@ -288,6 +317,91 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, return 0; } +static int axp717_usb_power_get_property(struct power_supply *psy, + enum power_supply_property psp, union power_supply_propval *val) +{ + struct axp20x_usb_power *power = power_supply_get_drvdata(psy); + unsigned int v; + int ret; + + switch (psp) { + case POWER_SUPPLY_PROP_HEALTH: + val->intval = POWER_SUPPLY_HEALTH_GOOD; + ret = regmap_read(power->regmap, AXP717_ON_INDICATE, &v); + if (ret) + return ret; + + if (!(v & AXP717_PWR_STATUS_VBUS_GOOD)) + val->intval = POWER_SUPPLY_HEALTH_UNKNOWN; + + ret = regmap_read(power->regmap, AXP717_PMU_FAULT_VBUS, &v); + if (ret) + return ret; + + v &= (AXP717_PMU_FAULT_VBUS | AXP717_PMU_FAULT_VSYS); + if (v) { + val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; + regmap_write(power->regmap, AXP717_PMU_FAULT_VBUS, v); + } + + break; + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + ret = regmap_read(power->regmap, AXP717_INPUT_CUR_LIMIT_CTRL, &v); + if (ret) + return ret; + + /* 50ma step size with 100ma offset. */ + v &= AXP717_INPUT_CUR_LIMIT_MASK; + val->intval = (v * 50000) + 100000; + break; + case POWER_SUPPLY_PROP_ONLINE: + case POWER_SUPPLY_PROP_PRESENT: + ret = regmap_read(power->regmap, AXP717_ON_INDICATE, &v); + if (ret) + return ret; + val->intval = !!(v & AXP717_PWR_STATUS_VBUS_GOOD); + break; + case POWER_SUPPLY_PROP_USB_TYPE: + return axp20x_get_usb_type(power, val); + case POWER_SUPPLY_PROP_VOLTAGE_MIN: + ret = regmap_read(power->regmap, AXP717_INPUT_VOL_LIMIT_CTRL, &v); + if (ret) + return ret; + + /* 80mv step size with 3.88v offset. */ + v &= AXP717_INPUT_VOL_LIMIT_MASK; + val->intval = (v * 80000) + 3880000; + break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + if (IS_ENABLED(CONFIG_AXP20X_ADC)) { + ret = iio_read_channel_processed(power->vbus_v, + &val->intval); + if (ret) + return ret; + + /* + * IIO framework gives mV but Power Supply framework + * gives uV. + */ + val->intval *= 1000; + return 0; + } + + ret = axp20x_read_variable_width(power->regmap, + AXP717_VBUS_V_H, 16); + if (ret < 0) + return ret; + + val->intval = (ret % AXP717_ADC_DATA_MASK) * 1000; + break; + default: + return -EINVAL; + } + + return 0; + +} + static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, int intval) { @@ -314,6 +428,22 @@ static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, return -EINVAL; } +static int axp717_usb_power_set_voltage_min(struct axp20x_usb_power *power, + int intval) +{ + int val; + + /* Minimum value of 3.88v and maximum of 5.08v. */ + if (intval < 3880000 || intval > 5080000) + return -EINVAL; + + /* step size of 80ma with 3.88v offset. */ + val = (intval - 3880000) / 80000; + return regmap_update_bits(power->regmap, + AXP717_INPUT_VOL_LIMIT_CTRL, + AXP717_INPUT_VOL_LIMIT_MASK, val); +} + static int axp20x_usb_power_set_input_current_limit(struct axp20x_usb_power *power, int intval) { @@ -354,6 +484,29 @@ static int axp20x_usb_power_set_input_current_limit(struct axp20x_usb_power *pow return regmap_field_write(power->curr_lim_fld, reg); } +static int axp717_usb_power_set_input_current_limit(struct axp20x_usb_power *power, + int intval) +{ + int tmp; + + /* Minimum value of 100mA and maximum value of 3.25A*/ + if (intval < 100000 || intval > 3250000) + return -EINVAL; + + if (power->max_input_cur && (intval > power->max_input_cur)) { + dev_warn(power->dev, + "reqested current %d clamped to max current %d\n", + intval, power->max_input_cur); + intval = power->max_input_cur; + } + + /* Minimum value of 100mA with step size of 50mA. */ + tmp = (intval - 100000) / 50000; + return regmap_update_bits(power->regmap, + AXP717_INPUT_CUR_LIMIT_CTRL, + AXP717_INPUT_CUR_LIMIT_MASK, tmp); +} + static int axp20x_usb_power_set_property(struct power_supply *psy, enum power_supply_property psp, const union power_supply_propval *val) @@ -376,6 +529,24 @@ static int axp20x_usb_power_set_property(struct power_supply *psy, default: return -EINVAL; } +} + +static int axp717_usb_power_set_property(struct power_supply *psy, + enum power_supply_property psp, + const union power_supply_propval *val) +{ + struct axp20x_usb_power *power = power_supply_get_drvdata(psy); + + switch (psp) { + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + return axp717_usb_power_set_input_current_limit(power, val->intval); + + case POWER_SUPPLY_PROP_VOLTAGE_MIN: + return axp717_usb_power_set_voltage_min(power, val->intval); + + default: + return -EINVAL; + } return -EINVAL; } @@ -399,6 +570,13 @@ static int axp20x_usb_power_prop_writeable(struct power_supply *psy, psp == POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT; } +static int axp717_usb_power_prop_writeable(struct power_supply *psy, + enum power_supply_property psp) +{ + return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN || + psp == POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT; +} + static int axp20x_configure_iio_channels(struct platform_device *pdev, struct axp20x_usb_power *power) { @@ -419,6 +597,19 @@ static int axp20x_configure_iio_channels(struct platform_device *pdev, return 0; } +static int axp717_configure_iio_channels(struct platform_device *pdev, + struct axp20x_usb_power *power) +{ + power->vbus_v = devm_iio_channel_get(&pdev->dev, "vbus_v"); + if (IS_ERR(power->vbus_v)) { + if (PTR_ERR(power->vbus_v) == -ENODEV) + return -EPROBE_DEFER; + return PTR_ERR(power->vbus_v); + } + + return 0; +} + static int axp20x_configure_adc_registers(struct axp20x_usb_power *power) { /* Enable vbus voltage and current measurement */ @@ -429,6 +620,14 @@ static int axp20x_configure_adc_registers(struct axp20x_usb_power *power) AXP20X_ADC_EN1_VBUS_VOLT); } +static int axp717_configure_adc_registers(struct axp20x_usb_power *power) +{ + /* Enable vbus voltage measurement */ + return regmap_update_bits(power->regmap, AXP717_ADC_CH_EN_CONTROL, + AXP717_ADC_EN_VBUS_VOLT, + AXP717_ADC_EN_VBUS_VOLT); +} + static enum power_supply_property axp20x_usb_power_properties[] = { POWER_SUPPLY_PROP_HEALTH, POWER_SUPPLY_PROP_PRESENT, @@ -447,6 +646,16 @@ static enum power_supply_property axp22x_usb_power_properties[] = { POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, }; +static enum power_supply_property axp717_usb_power_properties[] = { + POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, + POWER_SUPPLY_PROP_ONLINE, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_USB_TYPE, + POWER_SUPPLY_PROP_VOLTAGE_MIN, + POWER_SUPPLY_PROP_VOLTAGE_NOW, +}; + static enum power_supply_property axp813_usb_power_properties[] = { POWER_SUPPLY_PROP_HEALTH, POWER_SUPPLY_PROP_PRESENT, @@ -483,6 +692,18 @@ static const struct power_supply_desc axp22x_usb_power_desc = { .set_property = axp20x_usb_power_set_property, }; +static const struct power_supply_desc axp717_usb_power_desc = { + .name = "axp20x-usb", + .type = POWER_SUPPLY_TYPE_USB, + .properties = axp717_usb_power_properties, + .num_properties = ARRAY_SIZE(axp717_usb_power_properties), + .property_is_writeable = axp717_usb_power_prop_writeable, + .get_property = axp717_usb_power_get_property, + .set_property = axp717_usb_power_set_property, + .usb_types = axp813_usb_types, + .num_usb_types = ARRAY_SIZE(axp813_usb_types), +}; + static const struct power_supply_desc axp813_usb_power_desc = { .name = "axp20x-usb", .type = POWER_SUPPLY_TYPE_USB, @@ -507,6 +728,12 @@ static const char * const axp22x_irq_names[] = { "VBUS_REMOVAL", }; +static const char * const axp717_irq_names[] = { + "VBUS_PLUGIN", + "VBUS_REMOVAL", + "VBUS_OVER_V", +}; + static int axp192_usb_curr_lim_table[] = { -1, -1, @@ -594,6 +821,20 @@ static const struct axp_data axp223_data = { .axp20x_cfg_adc_reg = axp20x_configure_adc_registers, }; +static const struct axp_data axp717_data = { + .power_desc = &axp717_usb_power_desc, + .irq_names = axp717_irq_names, + .num_irq_names = ARRAY_SIZE(axp717_irq_names), + .curr_lim_fld = REG_FIELD(AXP717_INPUT_CUR_LIMIT_CTRL, 0, 5), + .usb_bc_en_bit = REG_FIELD(AXP717_MODULE_EN_CONTROL_1, 4, 4), + .usb_bc_det_fld = REG_FIELD(AXP717_BC_DETECT, 5, 7), + .vbus_mon_bit = REG_FIELD(AXP717_ADC_CH_EN_CONTROL, 2, 2), + .vbus_needs_polling = false, + .axp20x_read_vbus = &axp717_usb_power_poll_vbus, + .axp20x_cfg_iio_chan = axp717_configure_iio_channels, + .axp20x_cfg_adc_reg = axp717_configure_adc_registers, +}; + static const struct axp_data axp813_data = { .power_desc = &axp813_usb_power_desc, .irq_names = axp22x_irq_names, @@ -821,6 +1062,9 @@ static const struct of_device_id axp20x_usb_power_match[] = { }, { .compatible = "x-powers,axp223-usb-power-supply", .data = &axp223_data, + }, { + .compatible = "x-powers,axp717-usb-power-supply", + .data = &axp717_data, }, { .compatible = "x-powers,axp813-usb-power-supply", .data = &axp813_data, From patchwork Wed Aug 21 21:54:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13772192 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 39D06C52D6F for ; Wed, 21 Aug 2024 22:08:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RWYI1+rqxoAuP5ujwY5Es0pGFkBazrnSW9iCz4mY1l8=; b=Gk6QUNZIFQjx8oVxxtVMYyolFc 0fxjtPMAy4ftWiVZrVgei+N8UltHg/2uy2FytunemCwmy4q+7Vltme3dQ+Eo5ljY+FQe3lcexqtMA L8v1hG4fxqmesVN1h5CSMZ8tdsj6AbXnHNz2wCTGQJ/aTOf+jarjZqlvQG0z8Qt4l82zQabYUvL2d /nLgC+Ywy3iyc3lBMXtl9tXU11ilr5vpXJkw5zk36rofsYoYw0RMisb8iGgSEajwN04/kJAzMII2b gb2SAKQTgQQEFM64/ZFS4BC5AXtKIuVhfNGeONyD5zb7GkO+SfWv+i+H29ZmcXfTyN56r4WEEGaT+ VxjqN9uw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtUu-0000000AVoG-12Cr; Wed, 21 Aug 2024 22:08:08 +0000 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtKm-0000000AU9G-3biR for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 21:57:42 +0000 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3db1e4219f8so73151b6e.3 for ; Wed, 21 Aug 2024 14:57:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724277460; x=1724882260; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RWYI1+rqxoAuP5ujwY5Es0pGFkBazrnSW9iCz4mY1l8=; b=WlqMvqF6+XWQ6vMcUIlBNFt7y7MK9ePZ0sNbeCGYeJjjlT/H0ZWPhjXBgtJPsOqMl2 N0ZmP0Qey0bgzJj8Yp9p0kQumiIGiQxpcAsxU7OZiXX+zzdSjKyRFcR/C2m+gL2F7IgZ hgR8sTAX5+ZGLuffg9gxIKjPUXxlqGAjeBt42LYeiMPvFSej5F4zqf+T8OY8Un7KPeyV k1dgQX8hV+V9oPpYpKh+vv+r7cKeEmUp680TY2FtlagySRUkuxv3uJZh+hGD4wqHtqHT rTu6khrE15G/mAxqunzTHTnQW7unyx+Dyx1Kxkc/zsU5zHLLp7aoCcylf5qeBLTyMM1z 5xuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724277460; x=1724882260; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RWYI1+rqxoAuP5ujwY5Es0pGFkBazrnSW9iCz4mY1l8=; b=o4dlas+kLmVz+x9uLZaop/uuleyuLsHswXWginx0ivLJQbukLNHWoAJI3ValLuFgty TeYumlEpn2m3HDLV7KFGyMCScaLh6ZX7dIXQyOWNzja50QAYX4Ctab2Lf2O9ykoo8ehN JByK8U/lMukctu9BExSjm0IJzTtFpzs3eiIbO/7lfwfXltFzTYTVYZo7Kiq2viwSPTLC M31yTgqNJwEaSZe7K07RWMCO54CWt5VFueAn/V55O2Q5AK2AnrnSfsQ8guUmNCaquDqC c2f8tFjR22V0SbhAj3aYnx3+ELIu7rZJV0YAw1TInfdEW3P3H/gJ7+ROWS+zw7o/UzG5 n1FA== X-Forwarded-Encrypted: i=1; AJvYcCVXHT0iCHaHjFQof2iaasWV7pk2NGXEK2rXtXDdKles1DXPPOnPp4KSWYs5Pb6fWNmCYjqtGxXxUwVOTSTXNLpA@lists.infradead.org X-Gm-Message-State: AOJu0YyrLBqiEHLhpBBwTnd48c9zry+ubrhMXs01EUIsnlajnGLkog26 9lpHgQJeeshWnmkA4LmZmXmlpCb6wjhCmnLEUueQIdbuCLibVScl X-Google-Smtp-Source: AGHT+IEIJpkRZf3GerIDPrOK8qoWsbSJycVnWqKTAe676M+6Bx6GAz1aznK/Nt9mNbp/L4mJdvEtpw== X-Received: by 2002:a05:6808:1589:b0:3d5:61d9:fac1 with SMTP id 5614622812f47-3de1958ae6amr4046776b6e.46.1724277459987; Wed, 21 Aug 2024 14:57:39 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf:81a9:2325:e0f7:7376]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225555b6sm47070b6e.17.2024.08.21.14.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 14:57:39 -0700 (PDT) From: Chris Morgan To: linux-sunxi@lists.linux.dev Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com, mripard@kernel.org, tgamblin@baylibre.com, aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de, lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, jic23@kernel.org, jonathan.cameron@huawei.com, Chris Morgan , Philippe Simons Subject: [PATCH V4 14/15] power: supply: axp20x_battery: add support for AXP717 Date: Wed, 21 Aug 2024 16:54:55 -0500 Message-Id: <20240821215456.962564-15-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821215456.962564-1-macroalpha82@gmail.com> References: <20240821215456.962564-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_145741_016837_8FF9A54C X-CRM114-Status: GOOD ( 21.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chris Morgan Add support for the AXP717 PMIC battery charger. The AXP717 differs greatly from existing AXP battery chargers in that it cannot measure the discharge current. The datasheet does not document the current value's offset or scale, so the POWER_SUPPLY_PROP_CURRENT_NOW is left unscaled. Tested-by: Philippe Simons Signed-off-by: Chris Morgan --- drivers/power/supply/axp20x_battery.c | 438 ++++++++++++++++++++++++++ 1 file changed, 438 insertions(+) diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c index c903c588b361..f71cc90fea12 100644 --- a/drivers/power/supply/axp20x_battery.c +++ b/drivers/power/supply/axp20x_battery.c @@ -17,6 +17,7 @@ * GNU General Public License for more details. */ +#include #include #include #include @@ -32,9 +33,19 @@ #include #define AXP20X_PWR_STATUS_BAT_CHARGING BIT(2) +#define AXP717_PWR_STATUS_MASK GENMASK(6, 5) +#define AXP717_PWR_STATUS_BAT_STANDBY 0 +#define AXP717_PWR_STATUS_BAT_CHRG 1 +#define AXP717_PWR_STATUS_BAT_DISCHRG 2 #define AXP20X_PWR_OP_BATT_PRESENT BIT(5) #define AXP20X_PWR_OP_BATT_ACTIVATED BIT(3) +#define AXP717_PWR_OP_BATT_PRESENT BIT(3) + +#define AXP717_BATT_PMU_FAULT_MASK GENMASK(2, 0) +#define AXP717_BATT_UVLO_2_5V BIT(2) +#define AXP717_BATT_OVER_TEMP BIT(1) +#define AXP717_BATT_UNDER_TEMP BIT(0) #define AXP209_FG_PERCENT GENMASK(6, 0) #define AXP22X_FG_VALID BIT(7) @@ -49,11 +60,34 @@ #define AXP22X_CHRG_CTRL1_TGT_4_22V (1 << 5) #define AXP22X_CHRG_CTRL1_TGT_4_24V (3 << 5) +#define AXP717_CHRG_ENABLE BIT(1) +#define AXP717_CHRG_CV_VOLT_MASK GENMASK(2, 0) +#define AXP717_CHRG_CV_4_0V 0 +#define AXP717_CHRG_CV_4_1V 1 +#define AXP717_CHRG_CV_4_2V 2 +#define AXP717_CHRG_CV_4_35V 3 +#define AXP717_CHRG_CV_4_4V 4 +/* Values 5 and 6 reserved. */ +#define AXP717_CHRG_CV_5_0V 7 + #define AXP813_CHRG_CTRL1_TGT_4_35V (3 << 5) #define AXP20X_CHRG_CTRL1_TGT_CURR GENMASK(3, 0) +#define AXP717_ICC_CHARGER_LIM_MASK GENMASK(5, 0) + +#define AXP717_ITERM_CHG_LIM_MASK GENMASK(3, 0) +#define AXP717_ITERM_CC_STEP 64000 #define AXP20X_V_OFF_MASK GENMASK(2, 0) +#define AXP717_V_OFF_MASK GENMASK(6, 4) + +#define AXP717_BAT_VMIN_MIN_UV 2600000 +#define AXP717_BAT_VMIN_MAX_UV 3300000 +#define AXP717_BAT_VMIN_STEP 100000 +#define AXP717_BAT_CV_MIN_UV 4000000 +#define AXP717_BAT_CV_MAX_UV 5000000 +#define AXP717_BAT_CC_MIN_UA 0 +#define AXP717_BAT_CC_MAX_UA 3008000 struct axp20x_batt_ps; @@ -143,6 +177,39 @@ static int axp22x_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt, return 0; } +static int axp717_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt, + int *val) +{ + int ret, reg; + + ret = regmap_read(axp20x_batt->regmap, AXP717_CV_CHG_SET, ®); + if (ret) + return ret; + + switch (reg & AXP717_CHRG_CV_VOLT_MASK) { + case AXP717_CHRG_CV_4_0V: + *val = 4000000; + return 0; + case AXP717_CHRG_CV_4_1V: + *val = 4100000; + return 0; + case AXP717_CHRG_CV_4_2V: + *val = 4200000; + return 0; + case AXP717_CHRG_CV_4_35V: + *val = 4350000; + return 0; + case AXP717_CHRG_CV_4_4V: + *val = 4400000; + return 0; + case AXP717_CHRG_CV_5_0V: + *val = 5000000; + return 0; + default: + return -EINVAL; + } +} + static int axp813_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt, int *val) { @@ -188,6 +255,21 @@ static int axp20x_get_constant_charge_current(struct axp20x_batt_ps *axp, return 0; } +static int axp717_get_constant_charge_current(struct axp20x_batt_ps *axp, + int *val) +{ + int ret; + + ret = regmap_read(axp->regmap, AXP717_ICC_CHG_SET, val); + if (ret) + return ret; + + *val = FIELD_GET(AXP717_ICC_CHARGER_LIM_MASK, *val) * + axp->data->ccc_scale; + + return 0; +} + static int axp20x_battery_get_prop(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -340,6 +422,171 @@ static int axp20x_battery_get_prop(struct power_supply *psy, return 0; } +static int axp717_battery_get_prop(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy); + int ret = 0, reg; + + switch (psp) { + case POWER_SUPPLY_PROP_PRESENT: + case POWER_SUPPLY_PROP_ONLINE: + ret = regmap_read(axp20x_batt->regmap, AXP717_ON_INDICATE, + ®); + if (ret) + return ret; + + val->intval = FIELD_GET(AXP717_PWR_OP_BATT_PRESENT, reg); + return 0; + + case POWER_SUPPLY_PROP_STATUS: + ret = regmap_read(axp20x_batt->regmap, AXP717_PMU_STATUS_2, + ®); + if (ret) + return ret; + + switch (FIELD_GET(AXP717_PWR_STATUS_MASK, reg)) { + case AXP717_PWR_STATUS_BAT_STANDBY: + val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; + return 0; + + case AXP717_PWR_STATUS_BAT_CHRG: + val->intval = POWER_SUPPLY_STATUS_CHARGING; + return 0; + + case AXP717_PWR_STATUS_BAT_DISCHRG: + val->intval = POWER_SUPPLY_STATUS_DISCHARGING; + return 0; + + default: + val->intval = POWER_SUPPLY_STATUS_UNKNOWN; + return 0; + } + + /* + * If a fault is detected it must also be cleared; if the + * condition persists it should reappear (This is an + * assumption, it's actually not documented). A restart was + * not sufficient to clear the bit in testing despite the + * register listed as POR. + */ + case POWER_SUPPLY_PROP_HEALTH: + ret = regmap_read(axp20x_batt->regmap, AXP717_PMU_FAULT, + ®); + if (ret) + return ret; + + switch (reg & AXP717_BATT_PMU_FAULT_MASK) { + case AXP717_BATT_UVLO_2_5V: + val->intval = POWER_SUPPLY_HEALTH_DEAD; + regmap_update_bits(axp20x_batt->regmap, + AXP717_PMU_FAULT, + AXP717_BATT_UVLO_2_5V, + AXP717_BATT_UVLO_2_5V); + return 0; + + case AXP717_BATT_OVER_TEMP: + val->intval = POWER_SUPPLY_HEALTH_HOT; + regmap_update_bits(axp20x_batt->regmap, + AXP717_PMU_FAULT, + AXP717_BATT_OVER_TEMP, + AXP717_BATT_OVER_TEMP); + return 0; + + case AXP717_BATT_UNDER_TEMP: + val->intval = POWER_SUPPLY_HEALTH_COLD; + regmap_update_bits(axp20x_batt->regmap, + AXP717_PMU_FAULT, + AXP717_BATT_UNDER_TEMP, + AXP717_BATT_UNDER_TEMP); + return 0; + + default: + val->intval = POWER_SUPPLY_HEALTH_GOOD; + return 0; + } + + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: + ret = axp717_get_constant_charge_current(axp20x_batt, + &val->intval); + if (ret) + return ret; + return 0; + + case POWER_SUPPLY_PROP_CURRENT_NOW: + /* + * The offset of this value is currently unknown and is + * not documented in the datasheet. Based on + * observation it's assumed to be somewhere around + * 450ma. I will leave the value raw for now. + */ + ret = iio_read_channel_processed(axp20x_batt->batt_chrg_i, &val->intval); + if (ret) + return ret; + /* IIO framework gives mA but Power Supply framework gives uA */ + val->intval *= 1000; + return 0; + + case POWER_SUPPLY_PROP_CAPACITY: + ret = regmap_read(axp20x_batt->regmap, AXP717_ON_INDICATE, + ®); + if (ret) + return ret; + + if (!FIELD_GET(AXP717_PWR_OP_BATT_PRESENT, reg)) + return -ENODEV; + + ret = regmap_read(axp20x_batt->regmap, + AXP717_BATT_PERCENT_DATA, ®); + if (ret) + return ret; + + /* + * Fuel Gauge data takes 7 bits but the stored value seems to be + * directly the raw percentage without any scaling to 7 bits. + */ + val->intval = reg & AXP209_FG_PERCENT; + return 0; + + case POWER_SUPPLY_PROP_VOLTAGE_MAX: + return axp20x_batt->data->get_max_voltage(axp20x_batt, + &val->intval); + + case POWER_SUPPLY_PROP_VOLTAGE_MIN: + ret = regmap_read(axp20x_batt->regmap, + AXP717_VSYS_V_POWEROFF, ®); + if (ret) + return ret; + + val->intval = AXP717_BAT_VMIN_MIN_UV + AXP717_BAT_VMIN_STEP * + (reg & AXP717_V_OFF_MASK); + return 0; + + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + ret = iio_read_channel_processed(axp20x_batt->batt_v, + &val->intval); + if (ret) + return ret; + + /* IIO framework gives mV but Power Supply framework gives uV */ + val->intval *= 1000; + return 0; + + case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: + ret = regmap_read(axp20x_batt->regmap, + AXP717_ITERM_CHG_SET, ®); + if (ret) + return ret; + + val->intval = (reg & AXP717_ITERM_CHG_LIM_MASK) * AXP717_ITERM_CC_STEP; + return 0; + + default: + return -EINVAL; + } +} + static int axp22x_battery_set_max_voltage(struct axp20x_batt_ps *axp20x_batt, int val) { @@ -396,6 +643,35 @@ static int axp20x_battery_set_max_voltage(struct axp20x_batt_ps *axp20x_batt, AXP20X_CHRG_CTRL1_TGT_VOLT, val); } +static int axp717_battery_set_max_voltage(struct axp20x_batt_ps *axp20x_batt, + int val) +{ + switch (val) { + case 4000000: + val = AXP717_CHRG_CV_4_0V; + break; + + case 4100000: + val = AXP717_CHRG_CV_4_1V; + break; + + case 4200000: + val = AXP717_CHRG_CV_4_2V; + break; + + default: + /* + * AXP717 can go up to 4.35, 4.4, and 5.0 volts which + * seem too high for lithium batteries, so do not allow. + */ + return -EINVAL; + } + + return regmap_update_bits(axp20x_batt->regmap, + AXP717_CV_CHG_SET, + AXP717_CHRG_CV_VOLT_MASK, val); +} + static int axp20x_set_constant_charge_current(struct axp20x_batt_ps *axp_batt, int charge_current) { @@ -412,6 +688,24 @@ static int axp20x_set_constant_charge_current(struct axp20x_batt_ps *axp_batt, AXP20X_CHRG_CTRL1_TGT_CURR, charge_current); } +static int axp717_set_constant_charge_current(struct axp20x_batt_ps *axp, + int charge_current) +{ + int val; + + if (charge_current > axp->max_ccc) + return -EINVAL; + + if (charge_current > AXP717_BAT_CC_MAX_UA || charge_current < 0) + return -EINVAL; + + val = (charge_current - axp->data->ccc_offset) / + axp->data->ccc_scale; + + return regmap_update_bits(axp->regmap, AXP717_ICC_CHG_SET, + AXP717_ICC_CHARGER_LIM_MASK, val); +} + static int axp20x_set_max_constant_charge_current(struct axp20x_batt_ps *axp, int charge_current) { @@ -456,6 +750,19 @@ static int axp20x_set_voltage_min_design(struct axp20x_batt_ps *axp_batt, AXP20X_V_OFF_MASK, val1); } +static int axp717_set_voltage_min_design(struct axp20x_batt_ps *axp_batt, + int min_voltage) +{ + int val1 = (min_voltage - AXP717_BAT_VMIN_MIN_UV) / AXP717_BAT_VMIN_STEP; + + if (val1 < 0 || val1 > AXP717_V_OFF_MASK) + return -EINVAL; + + return regmap_update_bits(axp_batt->regmap, + AXP717_VSYS_V_POWEROFF, + AXP717_V_OFF_MASK, val1); +} + static int axp20x_battery_set_prop(struct power_supply *psy, enum power_supply_property psp, const union power_supply_propval *val) @@ -492,6 +799,42 @@ static int axp20x_battery_set_prop(struct power_supply *psy, } } +static int axp717_battery_set_prop(struct power_supply *psy, + enum power_supply_property psp, + const union power_supply_propval *val) +{ + struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy); + + switch (psp) { + case POWER_SUPPLY_PROP_VOLTAGE_MIN: + return axp717_set_voltage_min_design(axp20x_batt, val->intval); + + case POWER_SUPPLY_PROP_VOLTAGE_MAX: + return axp20x_batt->data->set_max_voltage(axp20x_batt, val->intval); + + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: + return axp717_set_constant_charge_current(axp20x_batt, + val->intval); + case POWER_SUPPLY_PROP_STATUS: + switch (val->intval) { + case POWER_SUPPLY_STATUS_CHARGING: + return regmap_update_bits(axp20x_batt->regmap, + AXP717_MODULE_EN_CONTROL_2, + AXP717_CHRG_ENABLE, + AXP717_CHRG_ENABLE); + + case POWER_SUPPLY_STATUS_DISCHARGING: + case POWER_SUPPLY_STATUS_NOT_CHARGING: + return regmap_update_bits(axp20x_batt->regmap, + AXP717_MODULE_EN_CONTROL_2, + AXP717_CHRG_ENABLE, 0); + } + return -EINVAL; + default: + return -EINVAL; + } +} + static enum power_supply_property axp20x_battery_props[] = { POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_ONLINE, @@ -506,6 +849,20 @@ static enum power_supply_property axp20x_battery_props[] = { POWER_SUPPLY_PROP_CAPACITY, }; +static enum power_supply_property axp717_battery_props[] = { + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_ONLINE, + POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_VOLTAGE_NOW, + POWER_SUPPLY_PROP_CURRENT_NOW, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, + POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_PROP_VOLTAGE_MAX, + POWER_SUPPLY_PROP_VOLTAGE_MIN, + POWER_SUPPLY_PROP_CAPACITY, + POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, +}; + static int axp20x_battery_prop_writeable(struct power_supply *psy, enum power_supply_property psp) { @@ -516,6 +873,15 @@ static int axp20x_battery_prop_writeable(struct power_supply *psy, psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX; } +static int axp717_battery_prop_writeable(struct power_supply *psy, + enum power_supply_property psp) +{ + return psp == POWER_SUPPLY_PROP_STATUS || + psp == POWER_SUPPLY_PROP_VOLTAGE_MIN || + psp == POWER_SUPPLY_PROP_VOLTAGE_MAX || + psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX; +} + static const struct power_supply_desc axp209_batt_ps_desc = { .name = "axp20x-battery", .type = POWER_SUPPLY_TYPE_BATTERY, @@ -526,6 +892,16 @@ static const struct power_supply_desc axp209_batt_ps_desc = { .set_property = axp20x_battery_set_prop, }; +static const struct power_supply_desc axp717_batt_ps_desc = { + .name = "axp20x-battery", + .type = POWER_SUPPLY_TYPE_BATTERY, + .properties = axp717_battery_props, + .num_properties = ARRAY_SIZE(axp717_battery_props), + .property_is_writeable = axp717_battery_prop_writeable, + .get_property = axp717_battery_get_prop, + .set_property = axp717_battery_set_prop, +}; + static int axp209_bat_cfg_iio_channels(struct platform_device *pdev, struct axp20x_batt_ps *axp_batt) { @@ -555,6 +931,27 @@ static int axp209_bat_cfg_iio_channels(struct platform_device *pdev, return 0; } +static int axp717_bat_cfg_iio_channels(struct platform_device *pdev, + struct axp20x_batt_ps *axp_batt) +{ + axp_batt->batt_v = devm_iio_channel_get(&pdev->dev, "batt_v"); + if (IS_ERR(axp_batt->batt_v)) { + if (PTR_ERR(axp_batt->batt_v) == -ENODEV) + return -EPROBE_DEFER; + return PTR_ERR(axp_batt->batt_v); + } + + axp_batt->batt_chrg_i = devm_iio_channel_get(&pdev->dev, + "batt_chrg_i"); + if (IS_ERR(axp_batt->batt_chrg_i)) { + if (PTR_ERR(axp_batt->batt_chrg_i) == -ENODEV) + return -EPROBE_DEFER; + return PTR_ERR(axp_batt->batt_chrg_i); + } + + return 0; +} + static void axp209_set_battery_info(struct platform_device *pdev, struct axp20x_batt_ps *axp_batt, struct power_supply_battery_info *info) @@ -578,6 +975,32 @@ static void axp209_set_battery_info(struct platform_device *pdev, } } +static void axp717_set_battery_info(struct platform_device *pdev, + struct axp20x_batt_ps *axp_batt, + struct power_supply_battery_info *info) +{ + int vmin = info->voltage_min_design_uv; + int vmax = info->voltage_max_design_uv; + int ccc = info->constant_charge_current_max_ua; + int val; + + if (vmin > 0 && axp717_set_voltage_min_design(axp_batt, vmin)) + dev_err(&pdev->dev, + "couldn't set voltage_min_design\n"); + + if (vmax > 0 && axp717_battery_set_max_voltage(axp_batt, vmax)) + dev_err(&pdev->dev, + "couldn't set voltage_max_design\n"); + + axp717_get_constant_charge_current(axp_batt, &val); + axp_batt->max_ccc = ccc; + if (ccc <= 0 || axp717_set_constant_charge_current(axp_batt, ccc)) { + dev_err(&pdev->dev, + "couldn't set ccc from DT: current ccc is %d\n", + val); + } +} + static const struct axp_data axp209_data = { .ccc_scale = 100000, .ccc_offset = 300000, @@ -603,6 +1026,18 @@ static const struct axp_data axp221_data = { .set_bat_info = axp209_set_battery_info, }; +static const struct axp_data axp717_data = { + .ccc_scale = 64000, + .ccc_offset = 0, + .ccc_reg = AXP717_ICC_CHG_SET, + .ccc_mask = AXP717_ICC_CHARGER_LIM_MASK, + .bat_ps_desc = &axp717_batt_ps_desc, + .get_max_voltage = axp717_battery_get_max_voltage, + .set_max_voltage = axp717_battery_set_max_voltage, + .cfg_iio_chan = axp717_bat_cfg_iio_channels, + .set_bat_info = axp717_set_battery_info, +}; + static const struct axp_data axp813_data = { .ccc_scale = 200000, .ccc_offset = 200000, @@ -623,6 +1058,9 @@ static const struct of_device_id axp20x_battery_ps_id[] = { }, { .compatible = "x-powers,axp221-battery-power-supply", .data = (void *)&axp221_data, + }, { + .compatible = "x-powers,axp717-battery-power-supply", + .data = (void *)&axp717_data, }, { .compatible = "x-powers,axp813-battery-power-supply", .data = (void *)&axp813_data, From patchwork Wed Aug 21 21:54:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13772193 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E2E00C52D7C for ; Wed, 21 Aug 2024 22:08:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IKDNW6bXNlNSyXqPzsgaizF0W6jVGjlSVIlGtBFqzzU=; b=I2RbYPrUWeNAHsrUacLeKgYq2w f1cVWTt8e37XSuv8sZGQBTfu9FBzqzuabIuI8M89YkS08R/NM5EKmMwIMiWWKHWMp3rvReXKlMCYD g7ZO504sBFtytsQjSOpKMM3nYsTvVLLRdSYH/jNs4dY7ovZtiJU2GXW7s5Z1vND0TaXD0pPuo/H8W TxkvRnC3xNkmwCPEJOmzy4ehIkeIVAObJuDNSoeOm8ufXEuxdUKsDFf9uBLQBEOqC9psBzBdIDsD8 sLs30zZgqfdng4UfM0NXxyA4gdy8EYaYZZcm/ilJUu6TVzM3ARec2kPwtQyVbGavqdW4yZaAVFP+i VFC54Djw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtVZ-0000000AVub-3YBL; Wed, 21 Aug 2024 22:08:49 +0000 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtKn-0000000AU9b-1uuv for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 21:57:43 +0000 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3db1eb76702so108047b6e.0 for ; Wed, 21 Aug 2024 14:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724277461; x=1724882261; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IKDNW6bXNlNSyXqPzsgaizF0W6jVGjlSVIlGtBFqzzU=; b=NXTDNRVN1qIxvse3+mB5IjpKK8YNjpWMgfLY5tiM8zk5K8bY1PiGRIfCHpCeQciT98 MbnORSeTtAx/XaCRPUb4XpLGh+2hH00x6yYB4Lq9fAobfF69mt+An//1B52r+Nfv8srW 7JhLQgN8+w03DxPN5Yp/QRdxHUeVXLn4X55TnXK8Fqgq1iC7iv7mxMy3zoB6lhLhG0PZ Enb9ZTtAsETLYPRpI2Q9uTZ8Lp/m9zbyI6FF3NkSV9JmzR/uLqkhaen1zLCsog2vLBvf 6Ne5w2LL0Hd8VfmAEAx78cC2Eb4kWbHOdeNogAccL01BguSYUrWl2h+6V+agAksy7gN9 g44A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724277461; x=1724882261; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IKDNW6bXNlNSyXqPzsgaizF0W6jVGjlSVIlGtBFqzzU=; b=HWVA9moGz2/gv/ShR3SrX9VztjunJyFEHZAAQC9EnOFWyEhE4nMws7PxnRuLEB+5Wy PhqaxgSAbusOLeSAv2fteC3etWecHbVZevgoID876KS8UlUxQxRhBCpzRjwZ8iRnNHtv jzI1CgjC4Ha5zYv1jjP7mDzdKgwIjEyDK5iB32F2/SLapWw2s2H0ZrxHmcJ9q2fjDqsr HCU8fEz0J1T8Japj9ckoWBOsfPeYqhLt/IbcDAC+qMl3NdfSkcoAbIHNAWqlt2xB+gl+ 0Gl93K5SB0t/dz0bu79UHY/Q7BznxGb41Llu0z9by5mmh429SqjeBdo2wy+HOuKfZw8y JT+A== X-Forwarded-Encrypted: i=1; AJvYcCUdZEDbYed9fjKqHIfM2Ht/gheLyp8tH9amZDBkIAm3Bp2992xJB/VrRoWmhK2JZt45jGMrBig8rOf4XSzwye5y@lists.infradead.org X-Gm-Message-State: AOJu0Yxw8U/VlIdNzhuZgM2+oT16q5eBVLXfDXow4GYFkdhuhlC54SBX lGzjIWOTVNG9BM8tvlJr+AWIDXRXN9gvRR53kB2oqlZb404olWYK X-Google-Smtp-Source: AGHT+IEot75d+ugH+I/XEKDoM+SkcrQKtwBcwYYvPfnFSXY6xNGTuXU9+zWMvMu4JO0C2GONh/4oUw== X-Received: by 2002:a05:6808:1892:b0:3d6:2ff3:937 with SMTP id 5614622812f47-3de1957157cmr4703770b6e.40.1724277460736; Wed, 21 Aug 2024 14:57:40 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf:81a9:2325:e0f7:7376]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225555b6sm47070b6e.17.2024.08.21.14.57.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 14:57:40 -0700 (PDT) From: Chris Morgan To: linux-sunxi@lists.linux.dev Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com, mripard@kernel.org, tgamblin@baylibre.com, aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de, lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, jic23@kernel.org, jonathan.cameron@huawei.com, Chris Morgan Subject: [PATCH V4 15/15] arm64: dts: allwinner: h700: Add charger for Anbernic RG35XX Date: Wed, 21 Aug 2024 16:54:56 -0500 Message-Id: <20240821215456.962564-16-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821215456.962564-1-macroalpha82@gmail.com> References: <20240821215456.962564-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_145741_526507_D5DEBB34 X-CRM114-Status: GOOD ( 12.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chris Morgan Add the necessary nodes for the AXP717 to allow for monitoring the USB and battery charger. Signed-off-by: Chris Morgan --- .../sun50i-h700-anbernic-rg35xx-2024.dts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arch/arm64/boot/dts/allwinner/sun50i-h700-anbernic-rg35xx-2024.dts b/arch/arm64/boot/dts/allwinner/sun50i-h700-anbernic-rg35xx-2024.dts index afb49e65859f..83b5c03b1bb8 100644 --- a/arch/arm64/boot/dts/allwinner/sun50i-h700-anbernic-rg35xx-2024.dts +++ b/arch/arm64/boot/dts/allwinner/sun50i-h700-anbernic-rg35xx-2024.dts @@ -21,6 +21,12 @@ aliases { serial0 = &uart0; }; + battery: battery { + compatible = "simple-battery"; + constant-charge-current-max-microamp = <1024000>; + voltage-max-design-microvolt = <4200000>; + }; + chosen { stdout-path = "serial0:115200n8"; }; @@ -217,6 +223,16 @@ axp717: pmic@3a3 { vin3-supply = <®_vcc5v>; vin4-supply = <®_vcc5v>; + axp_adc: adc { + compatible = "x-powers,axp717-adc"; + #io-channel-cells = <1>; + }; + + battery_power: battery-power { + compatible = "x-powers,axp717-battery-power-supply"; + monitored-battery = <&battery>; + }; + regulators { reg_dcdc1: dcdc1 { regulator-always-on; @@ -307,6 +323,11 @@ reg_cpusldo: cpusldo { /* unused */ }; }; + + usb_power: usb-power { + compatible = "x-powers,axp717-usb-power-supply"; + input-current-limit-microamp = <1500000>; + }; }; };