From patchwork Mon Aug 19 16:46:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13768628 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 AC51FC3DA4A for ; Mon, 19 Aug 2024 16:50:28 +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=pcsOwR+nB/fHNESVnjSucea+8y MWGsfeeHijxJteVLJ0ldaUDRJiHdJonx9NCd6uYQOphKvZ78vAEvXL3Ghvc2uyZy4OWuiXTHExgjM MaCXVkTqIhb7zeUHWNxF3Hp5NP2LX3Mxpe1lrj5VVQTpLs5zrVqM25IYloA3/sb6UmO43f+7c5gSR anRSJ6Yv6QulLq4oaXLNDVH3IwMy+5cmAyw9xI+QaaZouu3CL4m2Hdx3UUpbxyw4KF7Np0XAaO3UW fNMnsriRBMR3/aEtBLjc3gQqXNx5gdk80xJsWIYj8uKWJDcnDDX5h3pEdh7s/GTZVCEb8WJafl2S7 JDI7ROZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5aC-00000002F6a-0wny; Mon, 19 Aug 2024 16:50:16 +0000 Received: from mail-ot1-x32c.google.com ([2607:f8b0:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5Yi-00000002Ee5-2jxn for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 16:48:45 +0000 Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-709346604a7so2211397a34.1 for ; Mon, 19 Aug 2024 09:48:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724086123; x=1724690923; 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=Ob0hqckVzXIOCeNQLifN4KTTjREbqqM1he0GwkY5ekft/BIZHMT7hJDCe6HL4PfYgB PNb+zmYccp4AWqIo4fMjA8z0t75H/nXu2bI1YDF6ZSfI63s5IxPbbalfygb92cahpqL/ VRpkoddd4oQChCEVh2I2DpIpk/DKZXDYX0TB+VhGvOLxjsvhF/qckl7DsM8zNPEnwVsx gGvV8udpUHCUA3iwxk+2ItRWF6ZQxPpPlWIC12/v1YvxN/NinCFdBGGNzSfnBdPwvJsv Coj7LbYePJFj8m1V5PdoYIhJDNBRRhTvxdtTbNFXMMdHbwb7gILOYGRFnd1X5vo3IYqT 89oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086123; x=1724690923; 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=FGvBsirt5sg+VAb/lFrB6U9lzwDjjSaz32g09TbhZREcf/o/yGxw7qFBzXkJ7zdIyf EA4P5wXhS0nvZEoMvZE03ypokU63R1oTZhd0qyQTMMVl2gYnKz6kyGtAUY6SdjixuSrF /kb5HemA8Ka8CVHB3r/kyp5qT8bVKnkVmD7xC/4Cjia1eIhJpxowyqzkcv88hPm4z/v3 gOfxRDEle+x7SXlpRbAWdasKLvO/CyJteF5kLV0nhjR4mXjYivxMjLORqCCZAOogTHDA PV8CSo6C69rDc20HlEcpuKmiOggkEGem7B6jFbCJF4doaRKjW0aEY12i2X8xr+GoZdoe Ibjw== X-Forwarded-Encrypted: i=1; AJvYcCVWXD/L3VQ7nDxffBm0ITIQwQbDiimi9DntBpVHHx6upQVcxOn42P7iLa15YldoP89xzkIQdQdd9Bq+LkNkXKM6rjymAD4QycQFVh3Lj6HZ2W81nxk= X-Gm-Message-State: AOJu0YxJwohbv64aKjGut8MvRgctZr3qqR07xZwY7PKJurt6Zhfbnj6o UDrrXY6yRd733UO0yK/RPghyH3+tnejA/OLQJfb+dKmzmfBjq6t+ X-Google-Smtp-Source: AGHT+IEielcGYZURUYCkdiY1sv7fhZ692W4q8URFL/ta+IKVzCfe94ydQiEeafp1lIyynTDkxNazaw== X-Received: by 2002:a05:6830:6d09:b0:703:68e5:725b with SMTP id 46e09a7af769-70cac8c20bfmr15012910a34.24.1724086123067; Mon, 19 Aug 2024 09:48:43 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf::54]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70ca649c61csm2332428a34.26.2024.08.19.09.48.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:48:42 -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 V3 01/15] iio: adc: axp20x_adc: Add adc_en1 and adc_en1 to axp_data Date: Mon, 19 Aug 2024 11:46:05 -0500 Message-Id: <20240819164619.556309-2-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240819164619.556309-1-macroalpha82@gmail.com> References: <20240819164619.556309-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_094844_726887_63C28C28 X-CRM114-Status: GOOD ( 16.91 ) 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 Mon Aug 19 16:46:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13768629 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 86FB8C52D6F for ; Mon, 19 Aug 2024 16:51:05 +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=RGecUww/UqfC08nI/VERx3VT1P ItzBbpcihyUo+TPZWTDXreWxZKz34wgxhj78r7Rz4sWpVF4LaHyGe0H6Oket+GxJr3bmLGwwCeMFm nZ5DIT1n+jnbT8Mi77Fy/XJDTwfCo48XHBsBp6Ykz64/54Ce/1wHGIjZo+cK3Tvq/D9+aLZPgGiXq yesCDRkONOotyCvfYg8j8mHZsfFG8d1UpTYp/nC1JPW9epSTY2bJkZiw/zuq6ThtRr+Wu8ZBtnGDM fSt9clD3L69Ea54BCkCSs5P8wunE0OjUk+Bt7brjC+IbXfTKvt3hvtC/m1mTtkAaYuGzMEBK8+4wj Env1Gvag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5ap-00000002FDT-45Oz; Mon, 19 Aug 2024 16:50:55 +0000 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5Yj-00000002EeP-2k7g for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 16:48:46 +0000 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-70938328a0aso2351851a34.1 for ; Mon, 19 Aug 2024 09:48:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724086124; x=1724690924; 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=kThX6fWZ4aT5ResBMZ99XhWv3SwcRgOTR74zvaM6JsbxIb6AyUtixmzbVcDua+rS7w h2h40R5lTS/Ws9w5Po868QBzcGtdjvnB1ssnhQVpbUmYq6pB2a+I4YMCXpH5X0oXS2aI V4nFkl49P7u9QgDBUHSVIOhslugvCiPk3t+XAJW4BWr3BbjUAbPt+nLu/IVgscG9UEl/ fvzEXPO10fKMMuHGAM5xWOBmEdaGiOvjzK59RaJCZViKRqLHbK3ddJfDmy2VDMPA55Am 6RmKWGxAZtigfuhfXWGS7UZBXLIGMvhi6jo3xokPWp6zDabhkohxC57KDlve/a+YLIzy 38YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086124; x=1724690924; 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=i/vwIVD5Rx83PHVh1DMXKHwK18MtysEtjhb+slvC8TLWcasx4Z9VGyMWxephRK7Eap z8krFdalkcmFXQnwAZ073g+9sx5AeKkxNspL5gI5XqUddY239NtwDkg9oxhgZtpV2XYZ d5uscniOJSVN7qb3P2C0J7QQ5cEyPPyLc0PaT1pgSNwNMp5Uz/RcQkUCPnnxP2MuiCge KF9lCYGtA1SBjnmj1WvGt4PKor8UvtEdAbwXkObDAbtxul6zNrnuNagYlFEr7chHGXFF p7bl/eUjYA8+UjJ1P+CagxCr+ERRkDiS12Ost+kYx3thIS9MLdrMQUBFhhuo74HKs16u 5c9Q== X-Forwarded-Encrypted: i=1; AJvYcCXqSPf9yZiJF/UZYz9bdBH4wV0NRFTcrfTeD9W6n4RUF2WwxKU8mR4u7PUT2B9XR4gLpFbCigu/42LqnsPyin/CjhNOzdeau7X3NP/Xb5qTRl78y8s= X-Gm-Message-State: AOJu0YyXTm4Wr8cGirfcvjCYS8SLt60FYqz2LEH84tXbchXuUT455RjF KOHgI2TvxfvUKMwYJLeuZ33uHM6gRIS3dUgWuCXKz92VzMG1WPws X-Google-Smtp-Source: AGHT+IGRbx6BxU4vKawFjexC1H9e2LGpEq+T3o1X+Pv/qXuObKZyJbfFheTtea7zTF3p2BUGf2M5zw== X-Received: by 2002:a05:6830:d1c:b0:709:4936:d8fd with SMTP id 46e09a7af769-70cac8bf963mr15151806a34.29.1724086123933; Mon, 19 Aug 2024 09:48:43 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf::54]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70ca649c61csm2332428a34.26.2024.08.19.09.48.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:48:43 -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 V3 02/15] power: supply: axp20x_battery: Remove design from min and max voltage Date: Mon, 19 Aug 2024 11:46:06 -0500 Message-Id: <20240819164619.556309-3-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240819164619.556309-1-macroalpha82@gmail.com> References: <20240819164619.556309-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_094845_729389_F4D80C48 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 Mon Aug 19 16:46:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13768688 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 62649C3DA4A for ; Mon, 19 Aug 2024 16:51:48 +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=aqW4J+oSZuHveRCLt3CzeEbHM+ Mgen7bPCiH6bKpz96rmGxvnkSl4nYtSHhA7iI9iobOG3VJQyRzZ7qj3AXU+s6odS9P583Tb++elGD xnqFCvZSkh8I5gyNJkAKDsCP37IYD+jT1ll1fLFfz+v7qfQOeVvXQEAlxLr0lysoop+w0bQBZz3pJ QiHppnT4qtMC9YWAJ9fkAbqC8Z3lJ8epA/3/USJLFfDOTEUiYWJiIQFRA0U/3sbpOyjafR6Iyh79h eGfSbXVtUnfSfNDdzQdwCE9QcjRQAKGUN9V+FEPFk4XRqOAz+4KBsrOIoaJMdiqw1FxOVuiYpbr0m jg0RvB8Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5bT-00000002FMz-2XLf; Mon, 19 Aug 2024 16:51:35 +0000 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5Yk-00000002Eeh-17aO for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 16:48:47 +0000 Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-7093472356dso2377162a34.0 for ; Mon, 19 Aug 2024 09:48:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724086125; x=1724690925; 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=UudD4nHd6Jtr3hMWICuDGaH2fUc5YnEP6UqPp4ODxKs3I8yNoTCCXzT2YSnHmDS7s9 PnXVUm8Pr3EGGePY1jqaYAIMiprXJ5uRchKZH1y3jfl50gI0NpDZKYe3k30JnHDwSZl4 K8YK4lVkL7cVv5DxznL0V2UVIkFrK4J5qkptrSJHNXlavgE1ZMo1YcdM0oRDyAtSOjdT lzQinCmPUwiFszpqByPmBeeAGbPAqtBwYAkB9l8scuJBgwqYbU6baoNLamSGsVS+Ij+B hipnzyMyPLREQCA1xzGQ4GtSTrYHA1MkZc1x43OksYtGAG0E/eEtMOwa8W+xHx1+t/w6 zLiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086125; x=1724690925; 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=DohB94furCnoLGUb3L3r8DSIYOK1jNp1s54xWEyoXfQRTytWVGJgCph7GKKBojBtB6 B7eSK+WWQoaTq5NX5mhn4HiRLBaTMVirC+a3XC+olvK8JjsL7YFAYFs7hYkK/M2cZBa0 NATaoOf053ScFVfNorhFygtH+FDuJa49V+9ybOlM7SuBLOzbogtuKNxvhMWEfe9w60sR XJtPJt/KxYK4UIarw5MGydwMSuO7Ahu4wAx3FraAXPZ7c6DRvcCHCm/J2jWAIOojq66V pLKSdcrzWToOYp++9md1rtJcMIQqoXlNqX+CR1sw+VhJNLSIz7MUSSyyFu1ECn4KtgKR ts5A== X-Forwarded-Encrypted: i=1; AJvYcCX/Hh18KXW/y8OY89Tk5zcNM2VIcYQJAljz+tzqpvL9TwKSGEq4I4QJHKVV5SIQB7wyEgwNkS6uuh1ZT2tWPQxkCYrHejuPT/ZUUsc4J5bPR1tL49o= X-Gm-Message-State: AOJu0YxMLr0M0QkqPpoR5m0F5mgATSUrrrUBFd6/8BO/KJlneRCcPGc1 vFuc/ra8Rord+caGk6Hl9VCF44qiM/2WTbdUhQlbJ51Vo4zm5m3rwZcRAw== X-Google-Smtp-Source: AGHT+IEwdTajK32hPcu8uNm7Coe7QuoNGEKT0SOfI0VRHK0bdQK2q5Psfs0K6YXmcF7x1EbHUUprPA== X-Received: by 2002:a05:6830:3c8c:b0:709:419f:2ae7 with SMTP id 46e09a7af769-70cac8b1dbamr16175460a34.29.1724086124741; Mon, 19 Aug 2024 09:48:44 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf::54]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70ca649c61csm2332428a34.26.2024.08.19.09.48.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:48:44 -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 V3 03/15] power: supply: axp20x_battery: Make iio and battery config per device Date: Mon, 19 Aug 2024 11:46:07 -0500 Message-Id: <20240819164619.556309-4-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240819164619.556309-1-macroalpha82@gmail.com> References: <20240819164619.556309-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_094846_339865_0DEBB3C9 X-CRM114-Status: GOOD ( 23.08 ) 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 Mon Aug 19 16:46:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13768689 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 D442CC52D6F for ; Mon, 19 Aug 2024 16:52:24 +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=SAjiwva26SKLddNGNEoYJo4UOE OSaTJ3wy6IHNibZByn+wNo518X2kR/JW2vBx5yOASeZmYVPQO+HbRYyXIN2rLoh2fdyVtMsYIe0mE UP1dJqr16NQU8LOdvGqoWJdt/PBCUKNMekoOuGwrtuCiwUWQUKKmfxMucYUBm7IBzfhYNlStmsDYt aczqi8xZC7h201hgHmaYtRTkRUciwhrvKkF0WFVQUU0VAZn/1G9bowzuIgmE2DAJaOHD88aXGQuXx 8wiaypxrw+1tnouwmp+6Mgc00avZjfQZabIsqgmRzYGr3CnegukdCvm9r06ONHBPuoB4eHxwRAw8U qy2qIb0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5c7-00000002FVZ-0rjo; Mon, 19 Aug 2024 16:52:15 +0000 Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5Yl-00000002EfJ-2DrO for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 16:48:48 +0000 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-70943b07c2cso2573250a34.1 for ; Mon, 19 Aug 2024 09:48:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724086126; x=1724690926; 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=HSMQGjrSI2zpDaw28mZJlbOYgN5wxtNf1qT2mXmml5YhUajt6/zMTe/V1n4mnKLq3m L6h+H5l536kHREctta2CR+P2RAAQsnkaHChocd3WZONmPbUA8VJs3gvDWnk6h7rVftI7 2ZOil5wdNQUpnZhUj2Zdoi+2FH9C0j7E+5NhqJh7bC21YGBE4T/c1Tg1MiNNjjaBjsX/ ZXsFKxVcv+LNP3ZY4UZ8WwmVZVKp86x+0Oau5o+WFHTuzzkm9yHHFfbDZ2jx52hWUb+O T5jz1sKJO1KGufFMpoLIOoIashCOjbdT5/VOi+tG3ItIwsd/tlNHHhekWjHWyLHvjDqS nsCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086126; x=1724690926; 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=b0Rd3Y6nYyCIhqCx0wKgEG7cHZEpJdQRp6zeXaxu5H4d6vjOJISxUTIHLtXPQCPMZT NoGGaVSm+VOtixsvtRKd5ldfFmbQ2kT8DK9gThVqSPnmgV/2hw8u0epdSDrejJaE6vtI 0PJTTqDe3VDPbiC+pBSJ3ykAMXyKO0xK50VqTJSbgPdqI1v+wxRj0/TeqtlpycM0Xp47 cQ/P+V+w5U5b1urjoZSdPAj5f4jZnlyxWqH9oGH2f0Us7KYv6Nk9HT9ayvLKLBp/ZCCB hHi5aT6eeGxgm6rVlonOMPLusj8T7pSN6olwBeiaoRt3zl5Nh3f2BG6/e8mlaqx0ASWQ v1/A== X-Forwarded-Encrypted: i=1; AJvYcCV8pXiRUeWODXyja5Fxzr4XA5cN7IQslOyrH8elap5t/D5JSmTTcY/IIfRNHI/N+6lJogUHMpofXJrxDDSiOsGD5VI7wWwEutGfGcIIPweMEf4G740= X-Gm-Message-State: AOJu0YyvpBS5d2AFxFDDpjWYssAkeLqXRASpRpq/s2SvTgOBB9nxK/ac X3ig80/4iptOCNMiJZnby7n9FkwT1VwGpK/ywf+AqHC3sHE2Qs+Q X-Google-Smtp-Source: AGHT+IFKVHyXBq2kvibehw/FWwU6sMR+9rBonmmxLiBPSvlRFOSxmGmsGuw+ct2LJQdqTm9QFHZWEA== X-Received: by 2002:a05:6830:7107:b0:709:4060:1093 with SMTP id 46e09a7af769-70cac897e6amr15970781a34.22.1724086125773; Mon, 19 Aug 2024 09:48:45 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf::54]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70ca649c61csm2332428a34.26.2024.08.19.09.48.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:48:45 -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 V3 04/15] power: supply: axp20x_usb_power: Make VBUS and IIO config per device Date: Mon, 19 Aug 2024 11:46:08 -0500 Message-Id: <20240819164619.556309-5-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240819164619.556309-1-macroalpha82@gmail.com> References: <20240819164619.556309-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_094847_599858_24A84AC8 X-CRM114-Status: GOOD ( 18.95 ) 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 Mon Aug 19 16:46:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13768690 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 C70F7C52D6F for ; Mon, 19 Aug 2024 16:53: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=LDis15Hzp2Vx+5TQlBnC0YVroTqVlccFthHOCI8Z73Q=; b=hrxHUfBOWe9apw71+gPG1EXi6f aUxMzVx0fio2dAVwx5LpHE/8h7V/UTDsv/MK2+8JrneghVNveRhZCWIFYxPKIZyFhw5ahT2y7IVpS 0Tll+1qm5BxmNYxDWYYiQheRCIclhPJsdzMfim5wK+vSinobKAPT6ExaclXTvzTolrCWmvZ+VsjNY x2qzDW3PERQ0E1Fb+BXzFUzRGwTPuUcvjtIDtK5MifbwLCcJmihqThNNR09S7PB9JhOT6LVWmDwEc mG1k33HJDvOerDEBgPJu/MmT0QfZleBI1i4IZVaiImKsQH9HdzLbBi6v3+n6v5WXfgzwZcXRSSjiR EwAtYRVQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5ck-00000002Fe1-3RuM; Mon, 19 Aug 2024 16:52:54 +0000 Received: from mail-ot1-x335.google.com ([2607:f8b0:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5Ym-00000002Efe-0P5D for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 16:48:49 +0000 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-7093ba310b0so1929393a34.2 for ; Mon, 19 Aug 2024 09:48:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724086126; x=1724690926; 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=LDis15Hzp2Vx+5TQlBnC0YVroTqVlccFthHOCI8Z73Q=; b=mWGVtRH3XF0/hBlofZ+ch9AHr4M58rQ88cffKhZ5Lu9DK5Gstp8XX/cl97Dis8KxsL 60ShPWRShaOwoF6PcKOX+joAJciS6GycHdsAVX1+lTYa6nc68wmgP6GAIr93mzJH2Vtk W0Z7v0z6WbHDVFmLrrZmw0ysjsyPTCbL5gviW8klrOecxN4K2IHjY/P/SF7Zvx+HpRor ZdcagEmbsCuksuKbyWBug+x34JOoqbsv1nKRsdfkbqF0TVVNqumiq+r6wq5OdkbAMpRD 2naeRR+fQ3pwHUuLnMvqwLsUzl5BvK37Mu21wlpW0XP3CFlyMsjILA0ThhwOcjTcLIJO QjkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086126; x=1724690926; 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=LDis15Hzp2Vx+5TQlBnC0YVroTqVlccFthHOCI8Z73Q=; b=VZG61D2Gb38EyRKubdHSd1fsp1kIUCeIeFyMMZWAxLpPT8IveK1PUjWoZshkEQ9zME ljh6KgQ9UmxI3WnlNbWGCLpd5qvM6b4wZL4QQnEAb6PPm4Bdnm8dUVgrttuMBWN7sLtS ab63DBbNs/cxoLvArePw5BkQzrH2kKMST9Ta7QPKrwJ3VdygorG0X4lrAOvMm9HPHxGu 58e901I2LPKYry/wYCBtpcmLm7D6LTVQx2jI7O6JgvOBn7WCJmK0zsaOkoaRkRIznfa4 azGy6XMX/BQ1VGfHUEIeqPQMw7VcIFl9UDsIEwq14Cyr0hAt5UwPoRFexW+dsbWMkl/V gJAA== X-Forwarded-Encrypted: i=1; AJvYcCUf7aWM80Go0Dvt1WwxcdR38X1itF1FU+wz9Roju22u8PxGMqqqoQdk92NabUVh2xuro9vDQM955vtpmGKxv9Jb@lists.infradead.org X-Gm-Message-State: AOJu0Yzo901x/MMqVui1vSm7fMXzpCxPNZ79pV5deTt2yq8jKZENUj3m plw3w01kL7BxHoMOzeYe15rZUU1Y33FjRydcj89plqze0clzFz5K X-Google-Smtp-Source: AGHT+IHJmQOitznYw7nxXig16L2gz0qkKmEqys1jVwJ8LH/stIDVmGhzuz59B5CSI59rRM0lCJakKQ== X-Received: by 2002:a05:6830:448a:b0:70c:a547:1c3c with SMTP id 46e09a7af769-70cac83c080mr14115806a34.5.1724086126620; Mon, 19 Aug 2024 09:48:46 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf::54]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70ca649c61csm2332428a34.26.2024.08.19.09.48.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:48:46 -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 V3 05/15] dt-bindings: power: supply: axp20x: Add input-current-limit-microamp Date: Mon, 19 Aug 2024 11:46:09 -0500 Message-Id: <20240819164619.556309-6-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240819164619.556309-1-macroalpha82@gmail.com> References: <20240819164619.556309-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_094848_169321_AC53A805 X-CRM114-Status: GOOD ( 13.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 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 --- .../x-powers,axp20x-usb-power-supply.yaml | 69 ++++++++++++++++++- 1 file changed, 66 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..9cc300e78f60 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,74 @@ 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. 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,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: + 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 Mon Aug 19 16:46:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13768691 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 C42F7C3DA4A for ; Mon, 19 Aug 2024 16:53: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=wroKmzBQAn7lzKKJ1PdeFMhOwG oKEUic3qRPPQtvLJv5b2KP8VIPrWdHy4ZW2YUM3EBO7Sk1BvF3xKs1UdLo+7rb1um6nU1CFYLGfU6 Gv4YGtKk3BwAUeZvT2/XUlwFEp/eocVSDxw9AUU6J7zDa7nVwrSb7KDs+Hk4jjvuVt7t2AsS7mor6 lvcGnXYcdrP50HNEyacku8rX2UEk/5VRhS/4bSJ/zKo6SftlxtMIT6DYzv1zJEG0tGIWSHv1bOQVk y5esir26j4OQgjPHSJuhoKC2clriUZPNmNAt1D9KIwauRc8vLtQ0RWzOqn/cLXLWPtChtAYUgzPSq TNIRLa8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5dO-00000002FsO-3ZKP; Mon, 19 Aug 2024 16:53:34 +0000 Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5Yn-00000002EgB-08I6 for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 16:48:50 +0000 Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-7092dd03223so1100238a34.1 for ; Mon, 19 Aug 2024 09:48:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724086127; x=1724690927; 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=CaOJTDT0SiopfEbynaFhDXtqHHqeyOQHLqrOh0JP0NxQ7ijfcXosGDhz48u1b2dZPT c8E4r699TDmtAGYWFyLP9P8Ib5CZnRlcVErrfELK2KTaoFCpTpSi8UsNy2r4oIt18GkK JKU9U1VXX2fnY3QRu7zUZe571ZRQth3DE9TuS0l756+RjLYHgliv3huG3D6q96cUUtrS M/LC70kIpVrIhoZxI5+AbWhJyNwH61ZGUeGxpZ+adycvVMiSjmyYTKgQ8FjbkBWeAzyP YyFtGMeWFcbjaVN66X2FyCK42Fpof0dmM2tAK1ppBSzxBuVcgD5h8SJSa6Jz9z6pe4Tu MzoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086127; x=1724690927; 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=o6thE1FQp3vOZnIbMBbOotYAaRTwncu1TcBeJc+NJQapVpwH7ZameB7tecc3v8SdD6 ShCgMCUZ9BPTCajzymBeyFgm7ROvp2hF8uGWkEN+rBuI9vmmiK3EnwK61oi1SS836xYv Xhpe2gBdX3HAGfLmQbd6N7OQHlNLsklDxr3mFg//adQVcylvM6HgGj43zaXpB0PQFjsx PV/9qDJL5xYSPNPemFdKl1TKbXy8pjz2+DNfS6CERyFNEsZPzEIVme4Ws6Ocd/mQ8aAa uWe1DxELwi9jtiPuksfCCQvxMv2Z8rNN3liGfCPgmDjlYgAkguNUfT2yoAjRoU/D7wna JmFw== X-Forwarded-Encrypted: i=1; AJvYcCUqbSCRauxF1bdFBaJ/iEZr8IAtvsYBAc+mqh72sI+HbRq5JUwiUZtrisuOA/68p3ELQKreCCIPOYD7lPEu77mgsFVmD6zD774SIBLvvt5R88J2vkc= X-Gm-Message-State: AOJu0Yz6gcgLabQ93B6XZqyzEsVNUa+GAmuQKsoVp/911zRjYFgQNRa+ 3iPk2L5kgKtVkQxIErTWlyizlIsHEOaN0rMhJMvVNzknDwifS/l3 X-Google-Smtp-Source: AGHT+IGLpyFYSUV+cBCNRptV8yxiewNZEx5HrXXFCUBc5RJlJY+ALXntzTpuvudFQsRUtsorOOSeSQ== X-Received: by 2002:a05:6830:380d:b0:709:33ee:f578 with SMTP id 46e09a7af769-70cac84f622mr12959822a34.14.1724086127315; Mon, 19 Aug 2024 09:48:47 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf::54]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70ca649c61csm2332428a34.26.2024.08.19.09.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:48:47 -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 V3 06/15] power: supply: axp20x_usb_power: add input-current-limit-microamp Date: Mon, 19 Aug 2024 11:46:10 -0500 Message-Id: <20240819164619.556309-7-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240819164619.556309-1-macroalpha82@gmail.com> References: <20240819164619.556309-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_094849_097575_4D33B741 X-CRM114-Status: GOOD ( 16.66 ) 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 Mon Aug 19 16:46:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13768692 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 C2E85C52D6F for ; Mon, 19 Aug 2024 16:54:26 +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=pQ+BNWZuAFZGH3W3jfCF4ze3NG kXuhVVEuqGcGwOcjZgU1t+IxGywqNxYkCPViyfZgPhJNo3POKkW+busISqc0lPbkchkdIG8oSfi0G pczJSy24Y0vmmyO4VxoOwkR0EW7K7L3/EKDvSZB7wdHoyTErF6AW+MrJ52Sobd/cZDOpaxgA9i5BF 7lQoN7Tymw42Kjjdibqj+frgeIGmgwPPmnr3jH+LKB/KRvQVWxMP7M3qOhbYPIvk2wrIhHdi1Yaov 5gL+oP7yGKlm/oLBE0zcEsOapT/DzROJWg+tUQ+mTecmrwRfNz1OOUq4ZthWVNrl6ezEQlNDoxOvK DTMgACMQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5e3-00000002G6v-386C; Mon, 19 Aug 2024 16:54:15 +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 1sg5Yo-00000002EgY-02Bu for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 16:48:51 +0000 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3db157d3bb9so2596705b6e.2 for ; Mon, 19 Aug 2024 09:48:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724086128; x=1724690928; 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=IXGgbfTn2oUz9SOZvRXzfW4G+jy0bvyWZE+xLkPob1OCraxxMvqB/IbhwSXIIbSeHY IN7nj2aLOhYcSZAJ4OQrZ2mgvkeXvkIDFpV1dtuMS9/u4qpPyk884uUuCXZLSbrsvMpi NZa5e9NDF5SAZPSp4ULd/ykvjOQPi4Dy0ZKeIs4tJWabnBRj1zmjsSd+EBrvQjCDpM5h WfWR3EkVOtNq/rrmyXcckKdG1vKlDEaNWme6qSkNE7JUIwsLEQ7U49qAtRQ2HlfFz4S+ eRJd/+9ggkGJZY8WYl3n6f6wtNRN4F1qh5TRjg3BslXcD7svKbezqz8x3Q1pXZUc4cZy /mbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086128; x=1724690928; 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=G3oauvlrqg9cAg4vFJ+vD7qCH1KYEVcErmWLo8Lm4NXJSKys7FHRKXDCWCsoUtasjf zR8RMa4nBX5J/Itxekwm47hi+6GV77DQlC8kxvJ3/OGRD4zOXTotHtD8wAQBIEUi5Pxb Q2WAV2nFxWRFq1/5WD3NiUOVsuYP3wWl8OtEO0CBLCwtrtcqxoAR+G2nIcucob9Wzo4y DzZkL+8upUwBCI6VxtZa92neI9L20ncn0JGzTYUnIveG24I470k9SIWzH28MJr7L99dt Hhtt2+Ynry6WJFVDWxsLgskQoEgzA2oh/Yxfqojf2VMT9YXA9NSUB0215FfO92Zy6GzV MIbA== X-Forwarded-Encrypted: i=1; AJvYcCWoR/0xjbw1zrL/kMdfGJr4cO2tFFmAj8LWFHnW3pu3GPSumocBj/LY7SG8yUXWFjVloHKsc7hHkrmwM1u+kafCOS7u2V8UdYpaVQSHbOSjYqTA96E= X-Gm-Message-State: AOJu0YzhSF2NBVTQWNbl/Mjne12fObqjVNAif2nw6ZFMzwh9JDeUdIrg Lmj8r5w/VdnquAoeWP5oMeZzxtKUEChlA1jHOG8oMwWiRpLyVlvL X-Google-Smtp-Source: AGHT+IHO+Ajg81O2h/SkAHLfyjith17Lryqw1V96phGP04oeUSBU32OaTyHFcHhsC+FfxE2gv09F6A== X-Received: by 2002:a05:6830:631c:b0:700:d506:cfe9 with SMTP id 46e09a7af769-70cac8585aamr13557410a34.19.1724086128416; Mon, 19 Aug 2024 09:48:48 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf::54]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70ca649c61csm2332428a34.26.2024.08.19.09.48.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:48:47 -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 V3 07/15] dt-bindings: power: supply: axp20x-battery: Add monitored-battery Date: Mon, 19 Aug 2024 11:46:11 -0500 Message-Id: <20240819164619.556309-8-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240819164619.556309-1-macroalpha82@gmail.com> References: <20240819164619.556309-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_094850_073754_FC567119 X-CRM114-Status: GOOD ( 10.26 ) 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 Mon Aug 19 16:46:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13768694 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 94C13C3DA4A for ; Mon, 19 Aug 2024 16:55:48 +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=MlVlA8gaIgolKebNnqWJDgcJNt ErTxZ3YSz9Ib09KkSQoz2b6gYzNZ9h0j+mMxcHRhiP8Rb8aJpZKVGiDyrUQvBT2dQcwYFpwdYxfZA +z5Ozsr92rU4Gm9N3M/Uw7eZBV5UBClghdpkkIoITr3HK96hE/Weqvo8WJLZOW8m3iTq+BejhRROC SHf7Le5c0nPOb0mVtC7f2+QAF4ToJWQdqBxPmlARX1ZzQbNugGrU9okmnOdmKzLJ0AlapX4K1aKyh gAui7NgmW8QZRgbadX8KisrNkhKjCW2/iTX+Wj0oJ88Jfz0PZjh1W6n4tePlJUeSpVMbOJVJEhYSc KhUCvx5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5fM-00000002GWF-2xXY; Mon, 19 Aug 2024 16:55:36 +0000 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5Yp-00000002Egx-0iAf for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 16:48:52 +0000 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-709346604a7so2211460a34.1 for ; Mon, 19 Aug 2024 09:48:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724086129; x=1724690929; 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=NpRfwLP9yyA3lvSEL5LZlUPlm0Sa1UQwbcPhoDy6/SCk/jjop3LnCk75TYdakS/xUR wKjnd99LFFseeSjbHTGZ61h0T58Y7bAj/Zl/3zCBBe/wFI5jjf8HVJMqF49gvfsb3Yka LtVYqgRYGzSrIdlgVOfJYbaoLROlMra+rIXE/hkvJYX2/8RBBi6ff9/ryZMXm6UNEqzZ 7wrNaZd/HC0fCkKUv68KLEA7aeFAvFVmfgyatFlZvHrgoYbxyoS3+ltSNzqsGlk1WvKB gcElium4cUkDXYl/mr6l/cfdxuyId673/HpAh6LKe8mhAPL1lpTB6VkcoIDDPnSnNWmX d0kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086129; x=1724690929; 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=W1cAEsThoNbFLFhNAtV8JwsaIBiVtPZlYdvhULpCBM8W7NA0wprZfvlMVTnZ5FDy3b 0A35/255rWKl76K55QZHtAi1CT3e4Dh7lIT/jfJxVaVc66GOTpWdkU+QYHJHjzhxe0jk QQgASDcnr6N5dj9dIVgKpjKu28e+BfSdlkDWPpuE54F4N5CqdeAVt/x2KsVLz5eGehgn 2RVF1nZ8zB7h2V5FY93PT3f5415KNrE5HotCluHEXrRd1S+vzmu8+VB4/0abjzzRca8z yAdvxV+74TjygB+pcL2BdmGh+ybcOIPlXm0OEuDdFs3H/Ki9TusBcyvCVnrWAjs3dBpg Px0w== X-Forwarded-Encrypted: i=1; AJvYcCVoyDcU55pxy8qAG39HzIoSbbL8bGmWJS6DHTEuptsgyhz8VrSju4ejck3XOGwS0tWohbArIz5T5Qk9uwSDICeS/lHWCxw6KRBVJJ9j5AkXB+OtyeQ= X-Gm-Message-State: AOJu0YxELro+WSyuzChtHtHrGRLI1oyEqMoNbS7jDQy+NN5Cypm4RGw5 CzLD3/tV0AH/bsh1r5PVcXmqaqfUhaI9FR4OkfrI3YfxytCXLny8in7mDA== X-Google-Smtp-Source: AGHT+IHwC1bOkEu3UpOsz6uuWZJRs5JKYc9Qep4yjBeJPfyuZ2QbVvJZLOVGJiYVt7QAbcg5B43E8g== X-Received: by 2002:a05:6830:6088:b0:709:33b1:fc38 with SMTP id 46e09a7af769-70cac8d59b7mr16910408a34.29.1724086129542; Mon, 19 Aug 2024 09:48:49 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf::54]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70ca649c61csm2332428a34.26.2024.08.19.09.48.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:48:49 -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 V3 08/15] dt-bindings: iio: adc: Add AXP717 compatible Date: Mon, 19 Aug 2024 11:46:12 -0500 Message-Id: <20240819164619.556309-9-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240819164619.556309-1-macroalpha82@gmail.com> References: <20240819164619.556309-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_094851_240245_A68217A3 X-CRM114-Status: GOOD ( 11.16 ) 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 Mon Aug 19 16:46:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13768693 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 2FEF0C52D7C for ; Mon, 19 Aug 2024 16:55:05 +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=2mLcghtORtpXHj8P4yh8LryhEIqNeq4orRne8D1uG+I=; b=X8J9Hi+Xg991e6G1PAqD6klPkl IFwiQab04HZTMvqWhXemnDvrO4H/imXIqR6xhptSSRX0UVCfqC8qwib0qALdq0hI99sYKfqr0FYS3 Ss/Jfbud+B4GI8aCGOn0fxm+ejc+l/wRXcJRiJZY5tUHPlNw1F71zz5IHKgxzSx3w1qZMphSW71tg FiH0O7HfS/nRsoT7dlQpr3b223b3q9V6OAlPnVbtmH2zUYGmZPBec1o9szIMWZxKDyJ9K7wnJIG60 /hKt/lCUUvHW56/kx47Ow65l1MqgpKj58J0F8SlEWzqV76nE9VdgqDZk1ZYZFLrhtaXtjYwJZeTl5 744j2+WQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5eh-00000002GIi-1h8c; Mon, 19 Aug 2024 16:54:55 +0000 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5Yo-00000002EhL-42lW for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 16:48:52 +0000 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-709346604a7so2211466a34.1 for ; Mon, 19 Aug 2024 09:48:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724086130; x=1724690930; 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=2mLcghtORtpXHj8P4yh8LryhEIqNeq4orRne8D1uG+I=; b=E2bdBqkN8l9HS+FNRXSDzj2YN1ltjmlWgPrk9Bb2r3R0SvUrEtm6Zf7sBFOqgIEb1x txOxIU1eiB9ITer/uOYfPIAwLfvZuEFF9pEyUJJ3q0fTzcbsC06UbLTyCyWD2U0n08aA MpkwrwsECSCkcB8UxWOftLuvz+PEEQ1kZuzfg2BRvn5gc+Zt9YRDUCPZr3hqyv77zF/o jOseH7WEpGaiEx1hxJCLtt3Neq1EOJvIUxZ4WA12cs7V/WgrRTiABMTud6UZ+1qn+7mt 4R2rhL4E203Q+XspscOENi706F7EpBTrQv7AWTnZOXrT92ABAtvufRnYZ3kBnxYfZTCu YUZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086130; x=1724690930; 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=2mLcghtORtpXHj8P4yh8LryhEIqNeq4orRne8D1uG+I=; b=B9cw3C8INy67DEJcdNsv1b9L5phLlQfu9/jP+0Twg2wf0/KzX9V54zNUj6/iF++48R 4IuFe7eWzafx1jR/L/AuJc0SUryNStOg5qiDS9wV/zRH/hUxyqRKIU70V644pz/HXqzu nVjvt8TJHdbaz6TNVC2jBPu6HTjLqvbZ4esHvslKBIwqarLBf3tzKR/cwB6I99u18o4Y MfiCboWvbo3vUZkpIfJvPOq60hgmj/9zRzY5i43PAWQX5XxuZKxlBOntWG799bb+le4/ PQEtNdP8spZFgCOcB91Y9kyR4FM1JSHkmylmUJL7DgQk3NLVlAq4uYVdJ1oCU92ZqPaZ XlIA== X-Forwarded-Encrypted: i=1; AJvYcCU+Uh9uEdDq7ODO6r4ruDY9KydRQgUfjkh8dJyaM+JgOt67agJGjNfQwdglXz3cBPrBjFPreju+maLTguD7oFXKnrXG5BZMKDtYh4dy82MfTXINf2g= X-Gm-Message-State: AOJu0Yy64MEmHbGYCTWLcE0IbR3+80ig25NKaEMjoxDNJO/JPPLpSq7F J/DUuzZym/JRMyEA6hKIOKT+X1U25Fwy7VXFKAzYklA0p0VDXPnqNoaoRw== X-Google-Smtp-Source: AGHT+IGp0ZQPhwFlK9c0BFOFa4wuvrcDIPz31Bx64gvzmcJWhJHbsHHHQ++VNkm4g7m2Xj8Yo/IWaw== X-Received: by 2002:a05:6830:440f:b0:703:64c6:305b with SMTP id 46e09a7af769-70cac8491demr14520708a34.2.1724086130315; Mon, 19 Aug 2024 09:48:50 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf::54]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70ca649c61csm2332428a34.26.2024.08.19.09.48.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:48:50 -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 V3 09/15] dt-bindings: power: supply: axp20x: Add AXP717 compatible Date: Mon, 19 Aug 2024 11:46:13 -0500 Message-Id: <20240819164619.556309-10-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240819164619.556309-1-macroalpha82@gmail.com> References: <20240819164619.556309-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_094851_024221_735FE3A3 X-CRM114-Status: GOOD ( 11.15 ) 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 --- .../bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml | 1 + 1 file changed, 1 insertion(+) 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 9cc300e78f60..0a3b3d743d71 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 From patchwork Mon Aug 19 16:46:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13768696 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 5F5CDC3DA4A for ; Mon, 19 Aug 2024 16:57:10 +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=DQgf6z+FFrGFKRA/zPKul6XgHF rTJ+hPb+wPfbWTwMWPp9kIJntZvf9bHt4sLugS03/8mg2Rblu9DPXg0ZoqkuKw6CKd1E9o1tsZACl vK+09cmVg8dgvL4fVyKoJdACvm65jVtPIPe9S1UHUCbHI/sCZr6I25vGWd1vxXuA5dPXgKZl99/AU 6HP0+SKwlYcB5goCwJP2KAb4nLi/ffOiRyHlv612xPFOBrIuKGR8VjbUqiPwmFqY6YTOA7NtJC5jB hC1clHGwFhiWihGeo6phQiddH3LeiSQmp7KoXMRLZzubt4+uJEWLEvNbB1SJEipzo0eYLj/mzSjGW kwA2uO8w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5gg-00000002GxR-2SO0; Mon, 19 Aug 2024 16:56:58 +0000 Received: from mail-ot1-x32e.google.com ([2607:f8b0:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5Yq-00000002Ehy-2YnQ for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 16:48:53 +0000 Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-709339c91f9so2273611a34.0 for ; Mon, 19 Aug 2024 09:48:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724086131; x=1724690931; 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=B1QOmby4P7uMwnhR2gf7VjJ8wXwRj1kPdOESJ9HbsOvbmRiYd6eqF2fB24LK4jiEV5 Jwk9eUQl1BIwTqjw76utM6HyvTyxyBPxwnU0tHLqYpEvsvenTbMd8Xm7+iwzNjeQynNe AqSSo072vk49WJr3Jcncd6IvqJLFKsnXnkPmKg8eGx+3wqioY8KGP61cpXJmYr3UNBRr dvM6Y/QduS4NqtfW6JkW5E/kFWuCGSeKDQRanLoHqY2SEzPSUEka5eAUZa3G5UMiBDXI qsgobE3DnrihizQnrIZ3D3kIBSxDazYJIZuUkOxxPTSKlIUEFFb6t/Uxg0rjZr8/4Lgt yePw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086131; x=1724690931; 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=qQhDECrmMmimkxPLzLoMh4WfOLYuXmw4tAWyfm27PufUNbNXCYCMncFeubKBHJeOCn sSxvGFj3suhbaoO36HbSGICafbgpu4QjGYYNXZbpXiMNBz6DyNLZA14Z8SL4QUl5qFwH 4slDWzSoz60d3Pd+gX0zvE+65sckFuRNsbm8wb7eoG6Ok3Gjjw+xDJhXPWdM4EVtNQra bhWxFwDrJd/sDyFCQYqARtuFALf5L/RKAXy4kp4x6osiGkpltpqbjCSdM43wlnTEIaX/ quv8xrOKbd765Ic0pOURlAoXFHDSIfUZSMiITOGLjhbBbDr4Z0WOGe9wQtPUhiaZaXmk 6r5g== X-Forwarded-Encrypted: i=1; AJvYcCU60sigZsmZ6iKO97eUxeEMZG92WafJQydDCEq42iKYCWMx20tTITk4P/evLwsu6vTNhJ02j5O24T4H5AET49vvmfMh+31HsmbvOzQYYNIJk3jOGEk= X-Gm-Message-State: AOJu0YwWU1SdrMEdBND2sJRziSYeoQkbNmnDJj4KXatqj8aWRyCg3obr vbmS7UKg8JneL0c7Bo5044O0IPs1wyNq45AfoOvntfvlQspGcpiC X-Google-Smtp-Source: AGHT+IHClbSOtCizxu1DG+0TB0TXivck4+Ecm64YXTso2ATTPsQvJwx6/bvdNWCmxd6MYlrtFa74pQ== X-Received: by 2002:a05:6830:6787:b0:709:35ae:e793 with SMTP id 46e09a7af769-70cac8c1e30mr13425508a34.33.1724086131001; Mon, 19 Aug 2024 09:48:51 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf::54]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70ca649c61csm2332428a34.26.2024.08.19.09.48.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:48:50 -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 V3 10/15] dt-bindings: power: supply: axp20x: Add AXP717 compatible Date: Mon, 19 Aug 2024 11:46:14 -0500 Message-Id: <20240819164619.556309-11-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240819164619.556309-1-macroalpha82@gmail.com> References: <20240819164619.556309-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_094852_679517_0E250E52 X-CRM114-Status: UNSURE ( 9.89 ) 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 Mon Aug 19 16:46:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13768695 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 E02A1C3DA4A for ; Mon, 19 Aug 2024 16:56:25 +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=l6u+FjoNfAIrSP8vvJhv6wXYDtHqwQQPD0jrS5e6x2g=; b=Zg+dG3txuK6UKmuG+qkpDIvEvr 55N1RNlr/ZMSjSknFfmyIR6yp0x3ILolWg56oFJrdhCh2hWf2FaDCbhSY+CZ3tfBq+ijyzkF6mL7C VccjVJ/u2r2ISd+1FLbXxlPHJRrcNFOpCq1tyhV38akDa+JDNISu+FIQEzxDy9vl5RPYrWpCH/AK8 FOPp16aalLXSyJSoDP2j5SnDEk8gbBUm5vRcEvQAyg3Hl2Xc+FXpqc2UCjs8yT17LMc/xRXuvtT2s iSzIOI/GmqLQrKCwZ3ExcwJnn1TNh3UzA3yxLKWpAv7O5RLvXReeTBYuVg6GlmR4bGtnxiln6tRiH YLlLJjnQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5g0-00000002Ghj-2IXY; Mon, 19 Aug 2024 16:56:16 +0000 Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5Yq-00000002EiC-1zmA for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 16:48:53 +0000 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-70944d76a04so2647690a34.0 for ; Mon, 19 Aug 2024 09:48:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724086132; x=1724690932; 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=l6u+FjoNfAIrSP8vvJhv6wXYDtHqwQQPD0jrS5e6x2g=; b=em8y9vCEhudWFANkBSrgQjrv0oVxwzvuA1FeYmhdclWw50iVeHPfirINQ4esFO+41D MpH4GurGEgU5vOHL4UovvXQ5o+xVtwW2pbiRfKjFcDhEXlZiD7FcV0ypkAHxYyKhHLaj MtOOxhPUZZNbj8HsqX77h2IWAuHfOu0koAozSLo+gxhcPglU0uCf4fLNqsGk41tg1jzL VbKfrCABlNUX+SeBOAGFqKK9VC6NcmFmI2CkCvwSbILw+05PL5Pvsx3T/SIm13bIspNn XL/iOATAKcD8hpazQmqnnKauWIJw7in2PBWzHDozszGz6uOOUGpgDNoJVgRM2bqf3PpE TOXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086132; x=1724690932; 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=l6u+FjoNfAIrSP8vvJhv6wXYDtHqwQQPD0jrS5e6x2g=; b=Bpyo3JlGfFo/j9KofGIngm7Tm6HGiA7Pnx+11I5jMpnbgYTXXsszPf9j4uU0EFrbNM KJj8J47dVfaiQSd2Ej0ewiK5sH5c2yJlm/TUemX1KITPZg+nz1JhO+eRQstkb21raVBS 5vJsgdPov8bUy2W0RvfpHuPfmWWz/3JtIFbd8XyOGwguMQGqmxUe1BEXK4HMex0pqkXW lAtQjsBmCXat07uto5f7n1y2gdzXinCHwzty0Vu6dxmc0b70V+jdE4T2fr3S9U8YYona rg/qVbHEPHqR3OkgXsYFg2U+lZs0sIro/umHqiUJAiu6jHTpl4LFnk6oXgmeFw05/fVA Vj3g== X-Forwarded-Encrypted: i=1; AJvYcCWj/vlfO2fqFWmGgRNuXyMQAaHc1RYZ7QINyApkRna4xCKHLuFTo6QN/m+rY4xiX5xI9V+e/SakXoe+3V3LySvZFWtw+/XF+QVH4BZb/Fa0UDkCQq8= X-Gm-Message-State: AOJu0YwX0aBEWUgtIxktc9KrW+B+gUOm9tdHfDPv1n5O1CUekjZKgEMN rtewcb1svhXMBfsJGqDxljEHd5G5KwnPpo1kERikTbsHjWXm4gNm X-Google-Smtp-Source: AGHT+IE+qRwvUyn+ghEnlNA2FDgLk/Q7iiqC/0u7+41VM28tCsG8R3u8V5KG44yAdufJjxow4hsiug== X-Received: by 2002:a05:6830:3152:b0:703:629c:5e03 with SMTP id 46e09a7af769-70ded3813bfmr85939a34.13.1724086131790; Mon, 19 Aug 2024 09:48:51 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf::54]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70ca649c61csm2332428a34.26.2024.08.19.09.48.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:48:51 -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 V3 11/15] mfd: axp20x: Add ADC, BAT, and USB cells for AXP717 Date: Mon, 19 Aug 2024 11:46:15 -0500 Message-Id: <20240819164619.556309-12-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240819164619.556309-1-macroalpha82@gmail.com> References: <20240819164619.556309-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_094852_548213_C1BE49AD X-CRM114-Status: GOOD ( 15.12 ) 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 | 27 +++++++++++++++++++++++++++ 2 files changed, 51 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..f4dfc1871a95 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 @@ -484,6 +510,7 @@ enum { AXP717_CLDO3, AXP717_CLDO4, AXP717_CPUSLDO, + AXP717_BOOST, AXP717_REG_ID_MAX, }; From patchwork Mon Aug 19 16:46:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13768708 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 F37E6C52D6F for ; Mon, 19 Aug 2024 16:57:49 +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=k5qBf6Trd2Q2Z7Ma8hl95woMsA IjAh4whS60h2q+C175+v/PgnCDup+nJAgU9IVADa/QadT+2iL5td86hsn8iddgLm6uOh8/L2PS8bs 8nWOqIu/PWCNi3L3gw5Oq5tpgVP0eJSylE9N5BzDmcqALjIwBEbwkNu4hjcUONFycSDN1mAT49UG5 pF3asuQp4mvS9A/HiH2FRNWeWoDv9+lcsaozdMzorK4PhHvNdGYOpZXr0AW+nEYc6+63P9AJI6glU aztt0keupIelO0brW8JJdKMpY+skmK/rFtBm1PcddvkDRdw2kP9DPAmg9FKmQVdLnJx9hjcJiAZ9A Y9gFcTJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5hK-00000002H97-3C2m; Mon, 19 Aug 2024 16:57:38 +0000 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5Yr-00000002Eil-3mRj for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 16:48:55 +0000 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-70b3b62025dso3229285a34.0 for ; Mon, 19 Aug 2024 09:48:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724086133; x=1724690933; 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=RYp5/cBecFHYbIKjv8zIyom/dKVukU2nXKbhMPOeAedgd98TzYoWVgUM4BPNkCI3VE mk2DJr4kAiza8OcrVzV9gQKuYmQj61yiBWCx194+3ApdQgk1dwd8QARBokqfrb50MOT0 d+MdwGSU/60eafdpw2RpEVvifH4Mcr0ecH4zA9tgCtpZD/PmF5c3O6PdrVtYbuhUp1k8 6gVD6OvnqY+xkAbDO2aevfYq/0GgfqSHuGEDVS4bW9HvMRQsm5QnmFQpyPpRjAu/6r// /w/cMbU1zm/otUGewa5Zcb+9K21oz4Y4T6cr0l4f+/3KSsn/yjvreD+64C81v8xexe5e hR0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086133; x=1724690933; 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=UrJvdN35pvQpA9Xri3N957vq9oVWfd6A345Fhw4P3Cyw4JKpxi1xqTQcLjgH/GyoYk GNpMNSundGvBKZIEd0Atgx2OuOMwr2SOr4kQVOLywe+JjDeUGgozlGvFOV09s6nl03lg NkWNKuGt7mHO3HakYl3KfFcl9q5QDBmnR37vS0OCf2EAuPZUc6fiHh6MojQsz3pA1eyX mJX30JR01m8wHxdcnHd7ykb1zZDU6zMeSsVQHZGTjeRNeWggn6vHUqsGfTbfYZekbG8v Nv2L90/VDp3XnbopttQkleYsoyv5NJQIzkntJfe+a8NljcbJ6lpvAlqre3LohVn6RJpU 2RXA== X-Forwarded-Encrypted: i=1; AJvYcCUGjieaG09uGmrAqSsGwx0Ql6NUDNYhf0sopEPvSyC+w/+0p1d2ic9IVgX08kouiw84QkuLbzznKgbrvXTb8ks5bfuE7SRiwNDqwxxq2mJbSKJ3rm0= X-Gm-Message-State: AOJu0Yz8b9zDeMPDJUI77L/lCSxTedujFmH+lfD0eh0tNqWTs4X0QHZ+ yigVwwwxMpGWuqv+xN5vF0b9SeuNy62kaNn7AlzldNMYj6Gydmxa X-Google-Smtp-Source: AGHT+IEc7+tpPedG8d1UAzmwg0Z0Rl80RS/F7vLIrzHyuk5/lC5PzPFrNruqeYiMHG5CAprnj7uD0w== X-Received: by 2002:a05:6830:7192:b0:70a:9876:b76b with SMTP id 46e09a7af769-70cac83c08emr14127220a34.2.1724086132633; Mon, 19 Aug 2024 09:48:52 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf::54]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70ca649c61csm2332428a34.26.2024.08.19.09.48.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:48:52 -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 V3 12/15] iio: adc: axp20x_adc: add support for AXP717 ADC Date: Mon, 19 Aug 2024 11:46:16 -0500 Message-Id: <20240819164619.556309-13-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240819164619.556309-1-macroalpha82@gmail.com> References: <20240819164619.556309-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_094854_047502_FA23B1D5 X-CRM114-Status: GOOD ( 22.39 ) 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 Mon Aug 19 16:46:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13768709 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 F336EC52D6F for ; Mon, 19 Aug 2024 16:58: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=wzwbUBXpQ31q7HNv2dH+jmh+P3HKqC3um14cKU6HarE=; b=w/Ud4kNvnzFxi49ARiP0DHVYH9 1VsVeVif0k4xr2UTvdFqZYWFSAOgh/1G0K8Mwl1W0qwJRO3obOeVwxwWpPr4QsOxpzHWzNz3yk1Yj TiV0mwiwppVJaLqzCWz2YikaxsiBZBLrr90dQo9C8FDgzLjyq69sL2kGEUu9r0OVetpvFBYPfzg/H GYGx6rru13oKQyZY6F9uw1dSfBqmkj4YtenGESR2AhXalML2V+hYku950oGoEanomLR5WPXRSN41O D7z9NtjLzdyUHonaKJVLsFuIEGMDnqjfx62jrBHIob1paO4ZjIlAVEC52CA7904erGmknfVjndZKE /m7melRQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5hy-00000002HKP-1rfd; Mon, 19 Aug 2024 16:58:18 +0000 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5Ys-00000002EjI-3E8r for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 16:48:56 +0000 Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-7092dd03223so1100279a34.1 for ; Mon, 19 Aug 2024 09:48:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724086133; x=1724690933; 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=NwdcS5jf/rJ+zjTf0MESb4QFumXM/C1lcdiaGeyK/hceygkNuXyHCNuimygot8eo8t e3NwKQE0nJ0CtM1UkFH49BREW7rGeDy6Vd7IM6xdNG9V9tWTfKBBl+c4LHVaQxJgRSJp sEqiAAA4h/NQFgUM0iABDX3ekz4aIseSl4tvc2eK05+ZgKB41lfMZkvDBZbZSRtJx2e8 52UKfnkwMUvxfSlcSEaUERBd9A7JSluCRR9DZuhwPQlVvb2//eA3NvxtBe3mQKexj5n6 Eb4enw4ex1f+66dbK+pQnL0MixrLJwvQWR6BwjVbwWvx1LSzHZ8ZxvgiiG6dPm5SDMeg W9Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086133; x=1724690933; 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=HkNdbQmYNWVSZDXsjwDM9mM6JoRPxtMGn8WSviDaWGsFtldDYGzSj7j8iue+9N5Xdf VNL1Fopko80O/zfUVE44XZ8Slk/bOH73MM3qCnhacQLSrOtF5B+gmG9N0JxEWs5g1PdQ tbOT12ZaGbJo4B/cvJxPdPnJTP1RLhNH+tZdPeGhlfOvxbq9ZGEDP7qnH3/AA0v+wDCw nyKp1SdY9rOgH75XpUA/XktrBCfDor1PHNbX9ylNIkPRoCLXY2Kzkd+HGltvzUDP+2MA 7mCfYbQn+A8tEKolF4oxA1d5onxlZNenDDi4J51wb/HwQIKj6a2qdYTBiFD9jEQO/q3Z McAg== X-Forwarded-Encrypted: i=1; AJvYcCVbyi7IaBAdQU6NRwFFF2UhEMVAy+WyM1giPKSqbwMWPsGgctqZuavU5A5ilEwvrmjxBa/UofC8UquMwdgaNVkzHq6ZrMf4zdX5YgKYN1mCEFbWtdE= X-Gm-Message-State: AOJu0Yz6StWud1TePXc9lT4X+YniJti3XJYMy8pKlOY+TWy1u8xV90mt gTneJLPUcogJx7M1Nln8nKSo2oWFL1PB6ZfdnGRLNxf03bGIAYMr X-Google-Smtp-Source: AGHT+IFFYd4ZVwapqGVLHQyRGjAgCainehmvv8TwM5P2Gzk9wn1aPEvlnFBnJSxrHBUMh/MKn/hyAQ== X-Received: by 2002:a05:6830:6018:b0:707:1794:6f9c with SMTP id 46e09a7af769-70cac8901c7mr12590473a34.22.1724086133445; Mon, 19 Aug 2024 09:48:53 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf::54]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70ca649c61csm2332428a34.26.2024.08.19.09.48.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:48:53 -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 V3 13/15] power: supply: axp20x_usb_power: Add support for AXP717 Date: Mon, 19 Aug 2024 11:46:17 -0500 Message-Id: <20240819164619.556309-14-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240819164619.556309-1-macroalpha82@gmail.com> References: <20240819164619.556309-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_094854_851457_D77BD0A3 X-CRM114-Status: GOOD ( 23.08 ) 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 Mon Aug 19 16:46:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13768710 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 0533DC3DA4A for ; Mon, 19 Aug 2024 16:59:10 +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=rAOSNNqGHZk5eqNGgC5r2eAFOqJPQ2gWfhzwSVd1uSc=; b=bxoSoKWpdfSF3WPMIPHnhyCrtZ +bxI5hdWzTYwMiujp0+hCq2BuVin3Y34riGTwkEia+dGnkJjriYtYfEaiRz2zIGaAwnCCc8s8txHw itvf8fL6mqIKZaTQEnjQDPve8JPvLr1B3jDI5/q1n3djD+XvMenJOYNEHy1nepPYQHRfTesu/kqjT +kYKkyAj/VJ6Ski+ot0ZayX7vfjePYFDpUPWXcGYa15Tu7SWYYXi4Ww0cpYfiMVuh1I/RaSVZOUrw 89B6cJrFgYJcVq9oFh4L1NbiqPe1ox3yP1nQQe08rigYWqsTYgOsU8wnYzLOmf126EMpnv5mSIpsG R8sXXGCA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5id-00000002HZH-1x3A; Mon, 19 Aug 2024 16:58:59 +0000 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5Yt-00000002Ejh-2f1q for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 16:48:57 +0000 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-704466b19c4so2627048a34.0 for ; Mon, 19 Aug 2024 09:48:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724086134; x=1724690934; 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=rAOSNNqGHZk5eqNGgC5r2eAFOqJPQ2gWfhzwSVd1uSc=; b=lftj2C4Jm/U3QvO8i1Fhyzoa3VlB229s0Q1U5x7MISemeq7I3eL3nZVOPLUgkFmP52 W4BqcFSJD9QSbUXZSqos5ArKDaNJnh23/UQqaIinm45cIcGp+mCXqaD0ufzIbzk6/LW0 hPNf2+Bykf5O1XH0uv3uRghxhERasIubJW/Asvoj5S0LDsO2DPBvrkpamJlZZleMvU6k 81v+qzry5xtY1b33mrFG52xrul7EYjY4esjv7sJ0uWWZv2WsWcqHne/Q7o8s28PQXnmh K3Ix6aPLpga3Vh3W9QI8G64Glb6pHq/T0eRJ9dCYgWBdMTpOtbj5/b62xZjH78uKmXqK 9cdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086134; x=1724690934; 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=rAOSNNqGHZk5eqNGgC5r2eAFOqJPQ2gWfhzwSVd1uSc=; b=KpY+O5QfRjFBkgAFr4t19f+zmv+cmVSAM7xWl+bs0bncmQ9aIsr2kUeieNfxvYhlEW kEzRMFQPtxxY7pF4Wkzi4kYEBYCNFc47yTxaNx/cOLjx5+j4pG/Hrtjff1hrEnqm80y7 ThbiI+xwDrpCTUabqcd3xdfGTjKB/Yqr6vnJIkniLJtTwzAxAUxoPaeaI4bPKzNh5zcm znMyjk2EAAZIMBuM+/ybGpA3bk9DKz1TiSOvXpwgckS84OpbWFbnbdxcUKz1+13hVzqo +vpyrkOBla4y258nwtxvll0YvNjpQ2lERLnqwiUifQxyZSq8G2xjIlDkmCwN0a5tWxrv B31Q== X-Forwarded-Encrypted: i=1; AJvYcCXZxIfxWGyzMZ/JH5lnHJXj5vZHUwuOTnf0noCFYarCpt8JjH07SEpPI1iCQXtPuFiIAsnPDHjsWCQjHLV26v+f8hBwZPM1gnv7AlWCXTZ6LscBkhE= X-Gm-Message-State: AOJu0YwQHg51S9lMVw6NNWidQH2zNnXenof3sN8XaN8jp7AUvYVgmajS zdHfrKVBgCnloPHj9R0uvsG2uAhxJjgMVSQU4pT+dMuDp1NGrQkG X-Google-Smtp-Source: AGHT+IGu7XhEZxjvswryF9hPdHwsYydoIQuFBIN7kghC+9x3wK/wj9jECVR6gZW4Ujum4HwsNMc5HA== X-Received: by 2002:a05:6830:d07:b0:709:50b3:78c0 with SMTP id 46e09a7af769-70cac89bf42mr14963431a34.21.1724086134230; Mon, 19 Aug 2024 09:48:54 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf::54]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70ca649c61csm2332428a34.26.2024.08.19.09.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:48:53 -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 V3 14/15] power: supply: axp20x_battery: add support for AXP717 Date: Mon, 19 Aug 2024 11:46:18 -0500 Message-Id: <20240819164619.556309-15-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240819164619.556309-1-macroalpha82@gmail.com> References: <20240819164619.556309-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_094855_847610_AB9669D8 X-CRM114-Status: GOOD ( 21.45 ) 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 | 437 ++++++++++++++++++++++++++ 1 file changed, 437 insertions(+) diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c index c903c588b361..d43c11f27de6 100644 --- a/drivers/power/supply/axp20x_battery.c +++ b/drivers/power/supply/axp20x_battery.c @@ -32,9 +32,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 +59,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 +176,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 +254,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 +421,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 +642,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 +687,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 +749,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 +798,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 +848,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 +872,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 +891,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 +930,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 +974,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 +1025,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 +1057,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 Mon Aug 19 16:46:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13768711 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 9B3D7C52D7C for ; Mon, 19 Aug 2024 16:59:51 +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=pDgCKdCvmsY03Pik3wYi9u14QEc+d2Lmm2q5fMkp+bI=; b=OaqAKU+F4m90TEfH+t3Lmifg6D Y5b+BOamacp1xcxIuW92ftRMUp/1YSDwBFDYIQXbSqtDmRgveLCy8tw2NgsjS7nnt3xTnBKlNrTkR +96u8o8RJCPzxJB37DDi689JgeccVUeoDZlCrzb2VmsmOaTMSxPlqQRaLFd6eLOpSjKpzAWec7e0T mbY+rxukEBYFHU6tUgMHOsifHP4IiJhzKItRV/ck49TzgnKMYMD80swqlv7gUL/RNhKaOAYH8sm68 1C//8a/L5MbHMLbT8ILlTgQDZtekQtyAOfD4BUXq3pjknhqZjnQc54iDFbQnRfGa09W5ZE9hptaMD N1q6HFuw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5jI-00000002HpM-0j3W; Mon, 19 Aug 2024 16:59:40 +0000 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sg5Yu-00000002EkF-2LQG for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 16:48:57 +0000 Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-70949118d26so3724846a34.0 for ; Mon, 19 Aug 2024 09:48:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724086135; x=1724690935; 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=pDgCKdCvmsY03Pik3wYi9u14QEc+d2Lmm2q5fMkp+bI=; b=keqV+d7ks1eOa4nxT78tq4qN2xH67gSC/A05HcjCpUhMWzjva9ndEjhGRzwn/MLBGF FcbV8BVAiGiJ1OdKXX5GushHOsRAOqryNtiXR/AohSWibq19arRF2DnWk3ujz0bjxpfH A8OJa1E2+c5XgOCNEjS2z2AZm9SCO0emrNzPEg9DtuvE8TpZ+NGGLxhGKGDajfOUoOjM 3pPbV3OBSuljWFv29he+EfMdzNoV0f56CAqOufa2ro2LJARyHp0sgb41SSj63EYsRYIj 7x/aEV9LoARMJ6/w7LJztfUJOjXJ/JB027uWxwTbalLBLCvyRk6cDEOEYRdWghk+djzK OnSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086135; x=1724690935; 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=pDgCKdCvmsY03Pik3wYi9u14QEc+d2Lmm2q5fMkp+bI=; b=tgCMLODg0QOmPHHMLeFn5DsVsv6m+uM9U+XhYFRDvuaZcrQJTGaJmLX/yji6vXaRfQ on3/6c4NIlhQM496mHEhb0iZ+ASaZ8xMlXL4yIp0+m8ZShPFJMl214VCz3U/tEKuis3x Ak5T4xRiUCBj6d6sPlADeXOrXEomYVZI5mYX9tuHPgzMfrWOG4J5dcqE938WqYJ2fofR nxtUYVwDGkWar5xX/rb/gBlP6pDevljcyYNdMDfrOBjkFMFmY6Rj85pIrIIFqyljtXf8 BRzwvCQHA/Lod6P1V2ZVPp91/gdf/3Y9IUcFdlzRzZtg35zjDd6b8QfPWHXQ5WjHd8fM FmZw== X-Forwarded-Encrypted: i=1; AJvYcCWIj9KtU9ayg0zEAsuWNESe1UCyF+FGYbwVCwMeqKSkvFKaF/H3tK3QVvuGR5r8IIk9R4YOmG1OOtKxdf+nZLikWTXS0RS+3YFJ5m7+DnahjsalC90= X-Gm-Message-State: AOJu0YyIjy/1TcW9k9cdQmkzEWn9+t6uN3TVhvYxBly4i9j4ChCDnSDG Q3JSeDXO1O111U4KquBpeN0ScTO4ojG7/tjbirHla0FoluJbzLHY X-Google-Smtp-Source: AGHT+IEOCZLpFVa3etUE3cD8cEJLVRhuC8dwY9gXtzaL2mwue40C2B/W2Rq9aJPon4OTO+dgphhnHQ== X-Received: by 2002:a05:6830:358f:b0:709:4e4f:931a with SMTP id 46e09a7af769-70cac8a3c81mr16674258a34.22.1724086135220; Mon, 19 Aug 2024 09:48:55 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf::54]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70ca649c61csm2332428a34.26.2024.08.19.09.48.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:48:55 -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 V3 15/15] arm64: dts: allwinner: h700: Add charger for Anbernic RG35XX Date: Mon, 19 Aug 2024 11:46:19 -0500 Message-Id: <20240819164619.556309-16-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240819164619.556309-1-macroalpha82@gmail.com> References: <20240819164619.556309-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240819_094856_693332_8F84C1DC X-CRM114-Status: GOOD ( 12.32 ) 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 078b9ea3d9d0..18b63efae083 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@34 { 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>; + }; }; };