From patchwork Tue Apr 27 13:07:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 427942 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp4605411jao; Tue, 27 Apr 2021 06:05:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzi0LWqLsNHavjGMaurOCsrsK/hufAVRudFCFnLtahabAhyRLlGGJYLu2apbNGadUXov7SG X-Received: by 2002:a17:90a:77c8:: with SMTP id e8mr4941519pjs.69.1619528739476; Tue, 27 Apr 2021 06:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619528739; cv=none; d=google.com; s=arc-20160816; b=d1zW937tHXUTyU1GU7sDeriQ/4sI/oAP6y/3VhpjO1Lf6bIqrHPXuuxGNHrQpT0s+Z LVqOZ4LtHYc2qaMHPuX8BYblFooL0Cf68cuFmPufmKE+mhB5fvwdoJMxZpMzIaKAABYW 339884/iEro2cdX57URnsgqfXWlvEattx/rQ95HJBobfNUvk1F9cfSxv/Qx05pgqGX2W qIkXD8sawR+ALuPhH0QmwgYgLSnY6zGxFDdJrsKhMxMWJU6PEIKDNgty30B8//yZ+6pL 5W7gq/+g7yw1NPSOpE3nzC113jHI6NZVVV4zQZSROYDFrnHPRU8c2+Fwlf4Udi71UL5k aGPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=byleSoR3uVivo8lWUxItN76uGnD6h4WkxkvPblf1pgs=; b=D7RqwCqvr/FkRH8/MgnDHJwxQyDDTkke9C6a1Tnxy1kJUM6ItCt/XRx7PyTxaqqiM8 rdUcQFSdLs1h6OABJZv/XhMh5lPEzSQVuMm2aAXtR/jOLadQ1t93y15PyGLArV6YSN1G VglnEfpMPhKaCxyMCX8AHuFp8P2XWmybhWWO6alsTwhkMEpZeahHu2kAZh02MA32Os5z PPgCeKoYUfZjpbzObb7zk7SJeaat8WMTz+zuSf6/ICACrKUAgojlNbpQ64XKQQN9akT3 zjJY7mgM0/3F8qSUPvbdVqde36l8464uJ2oOzh2lIiAk5/jFFFuLx4Kviax43qLAScUQ 1d0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vm62xYFJ; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d14si2935005pjr.158.2021.04.27.06.05.39; Tue, 27 Apr 2021 06:05:39 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vm62xYFJ; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236001AbhD0NGU (ORCPT + 6 others); Tue, 27 Apr 2021 09:06:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235489AbhD0NGU (ORCPT ); Tue, 27 Apr 2021 09:06:20 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6210C061760 for ; Tue, 27 Apr 2021 06:05:36 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id h15so7148762wre.11 for ; Tue, 27 Apr 2021 06:05:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=byleSoR3uVivo8lWUxItN76uGnD6h4WkxkvPblf1pgs=; b=Vm62xYFJD6sXJffoKQwrG3Qm/9tpvPEPak3PAkkh+WJTaHtNBM6qd/5cvg9RxyEjz1 TgnkkMuGSip/FDy1c8of7lDfWBrJFVCihuOriM3Wkdas73I1WHrMiRCEyg8GrZwTtg+t sQNbKZ5tqzSRvcriiTrtzmn192RpuIJmHFQOOlOMeHS3xaR2pJCBcFz7+Ebc7r8RfTTA EPVVLlIiG7jJYP5vdeCjUsnRVNUPFzTCbBQDZa96wNHed+NSGq1AF/cEPLeBFJ/3Vd+Y qyVL/SRoCSDU7IXJID4bya/uiwb+6zcFKKhUSibsl7K8+bt22CwwNrgSG+Z14j1tNUzq 9DKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=byleSoR3uVivo8lWUxItN76uGnD6h4WkxkvPblf1pgs=; b=c51RJQT7IJSvr0dFAqYSRF5IckF4Kp++n/D+UVoyq7n58JBoo5Er2kGQmtEa2+lgja JC2SnUUX6X6KMT2IcVsOBU3TgdcGlLKjfBZ/rD9R2Y+Za8xatTLV73JFGK78Dyrqo6yz +qToKyNzQ1RliftX8xcHKSNhZjWwEG5or/CR0uVb2tUvHjSjiW8t84ZPcbsBMtWnys2N Ri5pcs1Dkyb0g33h0/MJY7+j1rHiEo6FGQoCoYGckgsf/xP4+A01DkBDUo1QHl7XJ+/C dP7zkS8dyV6EnXYKFg4EhtKt5bYTQ5F5eQ4+WjLfmQbxgpQ1ZgE8tIxo21l+w4AcAv0M z18w== X-Gm-Message-State: AOAM530WQj19U/zhvjAjPapNBA6wSFUeRENOfo5//XJq6Pu82LRKme3+ w6V11cn91uMM1uJDrU61UxxhMQ== X-Received: by 2002:adf:f6c8:: with SMTP id y8mr8991884wrp.325.1619528735458; Tue, 27 Apr 2021 06:05:35 -0700 (PDT) Received: from sagittarius-a.chello.ie (188-141-3-169.dynamic.upc.ie. [188.141.3.169]) by smtp.gmail.com with ESMTPSA id y19sm2488118wmj.28.2021.04.27.06.05.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Apr 2021 06:05:34 -0700 (PDT) From: Bryan O'Donoghue To: agross@kernel.org, bjorn.andersson@linaro.org, lgirdwood@gmail.com, broonie@kernel.org, robh@kernel.org, devicetree@vger.kernel.org Cc: wcheng@codeaurora.org, linux-arm-msm@vger.kernel.org, dmitry.baryshkov@linaro.org, bryan.odonoghue@linaro.org Subject: [PATCH v3 1/2] regulator: Add a routine to set the current limit for QCOM PMIC VBUS Date: Tue, 27 Apr 2021 14:07:11 +0100 Message-Id: <20210427130712.2005456-2-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210427130712.2005456-1-bryan.odonoghue@linaro.org> References: <20210427130712.2005456-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add hooks to regulator_get_current_limit_regmap() and regulator_set_current_limit_regmap() with an accompanying map of amperages. This lets us use the existing helper functions to map requested current settings to register bit-map/indicies. This change is required to elevate the default 2 Amps set by the bootloader to 3 Amps or indeed to constrain the value lower as the system design may dictate. The valid range is 500 mA to 3 A in increments of 500 mA. Cc: Mark Brown Signed-off-by: Bryan O'Donoghue --- drivers/regulator/qcom_usb_vbus-regulator.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) -- 2.30.1 diff --git a/drivers/regulator/qcom_usb_vbus-regulator.c b/drivers/regulator/qcom_usb_vbus-regulator.c index 457788b505720..2e627c2b6c512 100644 --- a/drivers/regulator/qcom_usb_vbus-regulator.c +++ b/drivers/regulator/qcom_usb_vbus-regulator.c @@ -16,13 +16,21 @@ #define CMD_OTG 0x40 #define OTG_EN BIT(0) +#define OTG_CURRENT_LIMIT_CFG 0x52 +#define OTG_CURRENT_LIMIT_MASK GENMASK(2, 0) #define OTG_CFG 0x53 #define OTG_EN_SRC_CFG BIT(1) +static const unsigned int curr_table[] = { + 500000, 1000000, 1500000, 2000000, 2500000, 3000000, +}; + static const struct regulator_ops qcom_usb_vbus_reg_ops = { .enable = regulator_enable_regmap, .disable = regulator_disable_regmap, .is_enabled = regulator_is_enabled_regmap, + .get_current_limit = regulator_get_current_limit_regmap, + .set_current_limit = regulator_set_current_limit_regmap, }; static struct regulator_desc qcom_usb_vbus_rdesc = { @@ -30,6 +38,8 @@ static struct regulator_desc qcom_usb_vbus_rdesc = { .ops = &qcom_usb_vbus_reg_ops, .owner = THIS_MODULE, .type = REGULATOR_VOLTAGE, + .curr_table = curr_table, + .n_current_limits = ARRAY_SIZE(curr_table), }; static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev) @@ -61,6 +71,8 @@ static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev) qcom_usb_vbus_rdesc.enable_reg = base + CMD_OTG; qcom_usb_vbus_rdesc.enable_mask = OTG_EN; + qcom_usb_vbus_rdesc.csel_reg = base + OTG_CURRENT_LIMIT_CFG; + qcom_usb_vbus_rdesc.csel_mask = OTG_CURRENT_LIMIT_MASK; config.dev = dev; config.init_data = init_data; config.of_node = dev->of_node;