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);