From patchwork Fri Aug 2 19:20: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: 13751903 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 70A20C3DA7F for ; Fri, 2 Aug 2024 19:26:23 +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=BXIA3blWOtk3v42sHMokRziAPu vi5Kcps71mAnefJNxKepsiPjW2N2/l7yyTXXFfj+XKZ3lL8/hZ4SmlW+AIX8/e5FB79Xr9kjZbTdp YBK42C2ucY4saLv93x6y7C1ghxmVCqMPE8BMPoI/rmZevYry2VJkuwm8r15KB8TUA08nE+5606xgD zLOsYghpXVEFRhOWq4PWlS88UAgWdYz5LaJ2zXHl+9HUoKdcweOHzVKgLvwX9FQXENZ4iE9JvGsP9 7oAbSgxYUNe3CTin8jT1gjxKVLKBxHgMO5sHASSTsZXqcICM1empd87AGN0Tol5nmtLdxofieyxCf Qrw25GzQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZxul-00000009rDV-3Riu; Fri, 02 Aug 2024 19:26:11 +0000 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZxrc-00000009qYN-29rg for linux-arm-kernel@lists.infradead.org; Fri, 02 Aug 2024 19:22:57 +0000 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3db1d4dab7fso5102993b6e.1 for ; Fri, 02 Aug 2024 12:22:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722626575; x=1723231375; 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=NSXPUf4Uq+SPH+8z4CdGEkwWrK1FPys3VGvkter1u099tThcGzh/Ty2087Ld1HsaX7 GgaWM1sxF3tqsSKvG2aG9BaW18Pij1YHkrRUV6ikEf63AeXKE5nAZ4jOpj4ryRZmChrR mJ7jb/MqgodTk2cPgZSWEP+a/oH4nywzWBhvn6K7CUNL9E6q1uKEfjH0NgrhhjVJGNKO wLAeuzk34k2j3wPb4LikNykL6iG+pG3G0kW3MZZALsgNx007jsPR4W3DqCO/5bSV04M2 Gvq0qGoC3CEnPCoUkZtY2+qJw2qKqNu4nLMROM4N623PUnxDugUckMr3JoRkAvQpqUO7 9RMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722626575; x=1723231375; 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=s6n35pUXt99zMbhGj4P08+q9GF3xnNjpjJPXxVGfaozKnpsoiBMZhN+EAre4Jj57/A EJSt7XP7Z7s8z4ggAsqbZvajUXfrmub7ZKmcWzbAmmzEtflnOMTA3fWu+XA+scamyGas E4LdHDKSNdujVTAlXjeSZ3SoutC7NzYCDIbc+1AYvAjfxwPL3tT9bHJ618tSJC/Q0C7R GI7XURmluhgyI4wc5LKdMQ/D9NQsnNrDxgGKT1AkVa2ua3mPaLLcfBp9Da4VYf0Xzb6L TVc3+xjai4HQUSbCiZNM9icyP448HFXAnjf+pxF9imUx7+sZ3cLhSwLriRXQfXJaRcpZ CyWA== X-Forwarded-Encrypted: i=1; AJvYcCX23EBA7h1WToHRwLxmxGCSgKLII04/yLkfoKOQE4JdyFxcWn1+GUcmC4khn+aBET/4ui9Jt+fzf8hEFb8jNvdhP0evo7XpzSs8wmw6tNg6HMLZMNU= X-Gm-Message-State: AOJu0YyczYK/r87LGkVBEBGf1NnwrdMALN1UplCfIwwHI53qYk60DwNz NcXIpOGCMTN12/kNJpeTM3VSWQhjRpL2uVlizBg/c5u/U/fcgTIa X-Google-Smtp-Source: AGHT+IGLrF7R/GoK7DvLxn2rE5wHYPa4hHdeD3olNUeNmJFauek8wLdUUrmSSS7uheaq9kYw3f4lNA== X-Received: by 2002:a05:6808:f8a:b0:3d9:dfef:d7c8 with SMTP id 5614622812f47-3db55817bf8mr5537828b6e.27.1722626574804; Fri, 02 Aug 2024 12:22:54 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf::54]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3db563b7065sm584592b6e.46.2024.08.02.12.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 12:22:54 -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, Chris Morgan Subject: [PATCH V2 06/15] power: supply: axp20x_usb_power: add input-current-limit-microamp Date: Fri, 2 Aug 2024 14:20:17 -0500 Message-Id: <20240802192026.446344-7-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240802192026.446344-1-macroalpha82@gmail.com> References: <20240802192026.446344-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240802_122256_581200_70A50520 X-CRM114-Status: GOOD ( 16.19 ) 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);