From patchwork Wed Aug 21 21:54:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Morgan X-Patchwork-Id: 13772184 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 04845C52D6F for ; Wed, 21 Aug 2024 22:02:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=VW8pLbjHmp58tJfvrusMBZ0t6nfvqNtc57mmOOIaTIw=; b=oiXAvl3qEuOcYqwILo998wiUHm rvJ8EvOxwx0C4JkEh+BCNBAhQN2AwYllRzR8Fjbrr27BwTOx3z8EOw2LkZSZgJAB/YVHuFf0uTp+K ivJMgBXHGNQVMBbI+eftHSiG6tMW6VajCkdjnAVKKnTyIuy/r8yePf13qjLIqcbEnBzdSkBVTb9bS kajsGd0jaxy4En+U8y0iP3gNr0+/2KtY6TNGw0YQzuEkCf1H6D4e2aJ1/mOiV05xjnIDcRRbvQye5 zR+MZxsV753wIGpN4gN5I9uP0jfsev8GSrgSGRw5356aU0yzAKZOMoOGViCOteVIg1xRwi0IM9nVq +VOOTQBg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtPT-0000000AUyg-2kEd; Wed, 21 Aug 2024 22:02:31 +0000 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgtKg-0000000AU5y-1UUw for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 21:57:35 +0000 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3de13d6bdcaso54911b6e.2 for ; Wed, 21 Aug 2024 14:57:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724277453; x=1724882253; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VW8pLbjHmp58tJfvrusMBZ0t6nfvqNtc57mmOOIaTIw=; b=Wl00aK2rg0hIRMyANHz2Y3FwYpIqoXql7KrDmdHLcffGZFP3rqLWF0UWoKl4b+F/RJ aEMyzvicUMtbLqtLFzUSjs1YTigm/1h65WiyxuVU5QAJXCl8icKkkDSr3sHKfiNCnalQ NgUS2G5Ngz8LItsrRn9wnJUiwZ3NUmg7+SvQDZuj7ryEEjqiEeudKhu9+3Sj7lmRgCya HTe5OOtHmeeIlGpayUwJLP8DBU0pFMYXCwIAIMy0kxWjui/k0t0gWItbmJUL8ll7k8pp mXQ0M148uQs4CHyomUl13xui/HNjaIAf1XEdKmZk2IoOQvkufT47uxT+TcNZ3OKE0ckd +7vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724277453; x=1724882253; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VW8pLbjHmp58tJfvrusMBZ0t6nfvqNtc57mmOOIaTIw=; b=cpklxjcZHH0e8fFN056r1QmQDlQqNKRXnKO1sQ+leZxBAEF/8zhY0h4QaM8qE8M+tK HqHWRlNchRg0FHqjbefq85qJChdCkUpcMrMOmgIYIOGm7c5EmwbZOhItXeINFqjetBwy WiSk+qpgIOMVvCRngMy2s3aKIjsKoZ9IEhq47O+K22DyeExDwkp5Cyi84hmNogTKaK8t 2bans80hs7RHg8tpHTDyo1mOiO5kVQrIRWLFti/fTwiuqr0069yxAl5psUi7nDjmfdY2 iANT93OoUVMgPalxjVc3v0gWsjOfhzfL8ILjV/2MksChSLzwok1W08CT+QOhehZF8tyl qVaw== X-Forwarded-Encrypted: i=1; AJvYcCW1/AgV01uZnS9Gw5ikiHsE9Jewk7Cslz3Ay0pUQQiM2EFlWgZChBrPTYGuyyZOBaGcgSUIGKvhRAMpgVaEt5DM@lists.infradead.org X-Gm-Message-State: AOJu0YyV+s/a6SMOlUin2IW9K+vu5HF7tsRxfZtYlHUwlDckMC/9kxAP qkO/grUBZPnsUhohtaD/LEBeRAZGOwCazOkO29uT+z7D6mzeILJE X-Google-Smtp-Source: AGHT+IHGclXhRe7MiZ2gdXv83D4GWjeaFVDAh8ffxoiueuIZjAXOFvrAwN7o6rMnhdMLZv0E2Dx/ug== X-Received: by 2002:a05:6808:2f07:b0:3db:198d:97cc with SMTP id 5614622812f47-3de19d20c0emr4500013b6e.33.1724277453646; Wed, 21 Aug 2024 14:57:33 -0700 (PDT) Received: from localhost.localdomain ([2600:1700:fb0:1bcf:81a9:2325:e0f7:7376]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3de225555b6sm47070b6e.17.2024.08.21.14.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 14:57:33 -0700 (PDT) From: Chris Morgan To: linux-sunxi@lists.linux.dev Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, quentin.schulz@free-electrons.com, mripard@kernel.org, tgamblin@baylibre.com, aidanmacdonald.0x0@gmail.com, u.kleine-koenig@pengutronix.de, lee@kernel.org, samuel@sholland.org, jernej.skrabec@gmail.com, sre@kernel.org, wens@csie.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, jic23@kernel.org, jonathan.cameron@huawei.com, Chris Morgan Subject: [PATCH V4 06/15] power: supply: axp20x_usb_power: add input-current-limit-microamp Date: Wed, 21 Aug 2024 16:54:47 -0500 Message-Id: <20240821215456.962564-7-macroalpha82@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821215456.962564-1-macroalpha82@gmail.com> References: <20240821215456.962564-1-macroalpha82@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_145734_454904_4D3AA35E X-CRM114-Status: GOOD ( 16.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chris Morgan Allow users to specify a maximum input current for the device. Some devices allow up to 3.25A of input current (such as the AXP717), which may be too much for some implementations. Signed-off-by: Chris Morgan --- drivers/power/supply/axp20x_usb_power.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index cd9e92f2ce71..69fbb5861934 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -80,6 +80,7 @@ struct axp20x_usb_power { struct iio_channel *vbus_v; struct iio_channel *vbus_i; struct delayed_work vbus_detect; + int max_input_cur; unsigned int old_status; unsigned int online; unsigned int num_irqs; @@ -323,6 +324,13 @@ static int axp20x_usb_power_set_input_current_limit(struct axp20x_usb_power *pow if (intval == -1) return -EINVAL; + if (power->max_input_cur && (intval > power->max_input_cur)) { + dev_warn(power->dev, + "reqested current %d clamped to max current %d\n", + intval, power->max_input_cur); + intval = power->max_input_cur; + } + /* * BC1.2 detection can cause a race condition if we try to set a current * limit while it's in progress. When it finishes it will overwrite the @@ -661,6 +669,18 @@ static int axp20x_regmap_field_alloc_optional(struct device *dev, return 0; } +/* Optionally allow users to specify a maximum charging current. */ +static void axp20x_usb_power_parse_dt(struct device *dev, + struct axp20x_usb_power *power) +{ + int ret; + + ret = device_property_read_u32(dev, "input-current-limit-microamp", + &power->max_input_cur); + if (ret) + dev_dbg(dev, "%s() no input-current-limit specified\n", __func__); +} + static int axp20x_usb_power_probe(struct platform_device *pdev) { struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); @@ -697,6 +717,8 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) if (IS_ERR(power->curr_lim_fld)) return PTR_ERR(power->curr_lim_fld); + axp20x_usb_power_parse_dt(&pdev->dev, power); + ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, axp_data->vbus_valid_bit, &power->vbus_valid_bit);