From patchwork Thu May 30 08:55:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Weber X-Patchwork-Id: 13679977 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 ABBD8C25B74 for ; Thu, 30 May 2024 08:57:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BQHW2l1bgoQDM4hNierKeUTemMBAGYeajCUUOpF5Z14=; b=C1li7TxymeJ2lD eGZHIiXQ0Ppq/3GTa/8Cp8Un0wOUxP6tcoSQksz9/96DVJwjHYLzZSHJr2+LpiJKyVK5O0rs/U2t9 ZVvwAAE4hhz9daTHZf6HVczUpH/1abvJKhr09gnetLVUeZ1arD+xMPnoJZOwuEUZ8twvI3tI+RQ2q dNXORQ6PvlbRsXrkcNHC/KEAcUEJqX6o7iQ6aF2sxuPwXWlGPgB19U4MCCodx98aLsd4WXFIvMbVE WB4GBIC47v9+Ss90rjabHzn8mHoDiS5HxZP58ktSbp12Z3HXSvPwKzBPcMRNcbfJd0y7mw5CvYWyT VTGagfxG/WhKYuIGkhgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sCbb9-00000006hv4-2l2a; Thu, 30 May 2024 08:57:23 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sCbaO-00000006haU-31gU for linux-arm-kernel@lists.infradead.org; Thu, 30 May 2024 08:56:39 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-52b79447c58so858429e87.1 for ; Thu, 30 May 2024 01:56:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717059394; x=1717664194; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=7RjpzD6bfEzWTvpqtXGEvDLHQS6WjNKNOtNtOUf/g0k=; b=de6jp25nF/+CijsA5k12IoWgwQPQloMN3rtxwpUVQniuxga4KyG95Q8RnZW8EoJTxe NdsNPrYice063pmwrd1A1Elz3NyLQ6KO9YyFye4Uc0htFaqnVQAM6Ip7Pbbg2EXOr+cY eJtaHVU/Pp3kj/Ytqvr2bxF+/LsaSfqQrJ+zrHgirU0y1gANTwPxsi4kWmt51G6e9NHU keXbxJmNKy9TGX7g1vuqSOXCMzBsMoUzQzDdoEDdmnVU+TZMH1MqKXF3ZvswqRe8jDe8 4iIRJe8xO3Vj7sMTO4na17uejY13bSG/0nn7HdTi1GC78blVlOQCVtNrM2EA8+BvWsCF GS8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717059394; x=1717664194; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7RjpzD6bfEzWTvpqtXGEvDLHQS6WjNKNOtNtOUf/g0k=; b=gl37uZac/ULUGy+I3vVWC84B+R7IqJ35/MwAIc1fMEQijO91ppYGqFxhOJ0V5eVnSR LXxHJ+IjlBe2TG64BWoaCL/f4I358kpVh9j1ISbctJPs2uh53rk73a2JL3a+nF0egZmz NRG4AfNjkCDA13Q9h4pAQEW/Uxlrdn5yJzT+KX7pZWtc+sLJ/kv5njbQdySNsGTSePGu OUktUuxyPGa6DgsWEGmgKDFChYMuP6QQ/ADMgGAurNgcRx2DI9mN+wNCAzJQJEGvx22E Mem+g49QPLx/8OJcXtYdgQk2DRCpmTcKmOcEhMoZvsAYiC5bFcaR8dQ+QlUgDg1gdBS4 Qn6w== X-Forwarded-Encrypted: i=1; AJvYcCU3Z/tsrj96s+Poqak8IplGj6py+FkzIudWfGAPKy+ArMK4Pd2L1QYe7SqBWagZD0mf+TrFMtZenJWhqdR5EEBBjW6jkjgqlosMLd1XK2WJOgWKeCg= X-Gm-Message-State: AOJu0YzpdwLBTp/E9i14d3CPSeYSfTvHVaOfeWri4/mnGxAhQuOHO/hW OBHAACY31a09bSUkKmyU29CGmtElkgcJZ8EziODWWu0+yuGTxtAi X-Google-Smtp-Source: AGHT+IHwPpyulXExjGnPKagykwpS32TIBll7xV05JGGq+Yi/BHyTXoe0cwkmsoRZnXimftPoX515uA== X-Received: by 2002:a05:6512:1183:b0:52a:de09:283a with SMTP id 2adb3069b0e04-52b7d43b001mr1194683e87.37.1717059393912; Thu, 30 May 2024 01:56:33 -0700 (PDT) Received: from hex.my.domain (83.8.128.191.ipv4.supernova.orange.pl. [83.8.128.191]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a626cc500a1sm798430166b.125.2024.05.30.01.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 01:56:33 -0700 (PDT) From: Artur Weber Date: Thu, 30 May 2024 10:55:56 +0200 Subject: [PATCH RFC 06/11] power: supply: max77693: Set charge current limits during init MIME-Version: 1.0 Message-Id: <20240530-max77693-charger-extcon-v1-6-dc2a9e5bdf30@gmail.com> References: <20240530-max77693-charger-extcon-v1-0-dc2a9e5bdf30@gmail.com> In-Reply-To: <20240530-max77693-charger-extcon-v1-0-dc2a9e5bdf30@gmail.com> To: Krzysztof Kozlowski , Chanwoo Choi Cc: Sebastian Reichel , Rob Herring , Conor Dooley , Lee Jones , Krzysztof Kozlowski , Alim Akhtar , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Henrik Grimler , Wolfgang Wiedmeyer , Denis 'GNUtoo' Carikli , Artur Weber X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1717059384; l=3318; i=aweber.kernel@gmail.com; s=20231030; h=from:subject:message-id; bh=C8RQpwCwOR+YYCuseUykropyLMG3kS1Is6uGMemnREw=; b=ot9Ju3EGJBen9DJEc/vVfO7LgQgKOaa5PtRG8GPVMQY6vN+iI9zaPuXzBkUtX4sQCTlX+dRwl K0xAp8pivroAnNNGQt/G9m+i0vfmTOy0gZ4h89eqN2J3XET461eIXRg X-Developer-Key: i=aweber.kernel@gmail.com; a=ed25519; pk=RhDBfWbJEHqDibXbhNEBAnc9FMkyznGxX/hwfhL8bv8= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240530_015636_880619_CDAE5E82 X-CRM114-Status: GOOD ( 16.70 ) 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 There are two charger current limit registers: - Fast charge current limit (which controls current going from the charger to the battery); - CHGIN input current limit (which controls current going into the charger through the cable, and is managed by the CHARGER regulator). Add functions for setting both of the values, and set them to a safe default value of 500mA at initialization. The default value for the fast charge current limit can be modified by setting the maxim,fast-charge-current-microamp DT property; the CHGIN input current limit will be set up later in the charger detection mechanism. Signed-off-by: Artur Weber --- drivers/power/supply/max77693_charger.c | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/power/supply/max77693_charger.c b/drivers/power/supply/max77693_charger.c index 894c35b750b3..d59b1524b0a4 100644 --- a/drivers/power/supply/max77693_charger.c +++ b/drivers/power/supply/max77693_charger.c @@ -28,6 +28,7 @@ struct max77693_charger { u32 min_system_volt; u32 thermal_regulation_temp; u32 batttery_overcurrent; + u32 fast_charge_current; u32 charge_input_threshold_volt; }; @@ -591,6 +592,35 @@ static int max77693_set_batttery_overcurrent(struct max77693_charger *chg, CHG_CNFG_12_B2SOVRC_MASK, data); } +static int max77693_set_input_current_limit(struct max77693_charger *chg, + unsigned int uamp) +{ + dev_dbg(chg->dev, "CHGIN input current limit: %u\n", uamp); + + return regulator_set_current_limit(chg->regu, (int)uamp, (int)uamp); +} + +static int max77693_set_fast_charge_current(struct max77693_charger *chg, + unsigned int uamp) +{ + unsigned int data; + + data = (uamp / 1000) * 10 / 333; /* 0.1A/3 steps */ + + if (data > CHG_CNFG_02_CC_MASK) { + dev_err(chg->dev, "Wrong value for fast charge current\n"); + return -EINVAL; + } + + data <<= CHG_CNFG_02_CC_SHIFT; + + dev_dbg(chg->dev, "Fast charge current: %u (0x%x)\n", uamp, data); + + return regmap_update_bits(chg->max77693->regmap, + MAX77693_CHG_REG_CHG_CNFG_02, + CHG_CNFG_02_CC_MASK, data); +} + static int max77693_set_charge_input_threshold_volt(struct max77693_charger *chg, unsigned int uvolt) { @@ -668,6 +698,15 @@ static int max77693_reg_init(struct max77693_charger *chg) if (ret) return ret; + ret = max77693_set_fast_charge_current(chg, chg->fast_charge_current); + if (ret) + return ret; + + ret = max77693_set_input_current_limit(chg, + DEFAULT_FAST_CHARGE_CURRENT); + if (ret) + return ret; + return max77693_set_charge_input_threshold_volt(chg, chg->charge_input_threshold_volt); } @@ -703,11 +742,17 @@ static int max77693_dt_init(struct device *dev, struct max77693_charger *chg) chg->charge_input_threshold_volt = DEFAULT_CHARGER_INPUT_THRESHOLD_VOLT; + if (of_property_read_u32(np, "maxim,fast-charge-current-microamp", + &chg->fast_charge_current)) + chg->fast_charge_current = DEFAULT_FAST_CHARGE_CURRENT; + return 0; } #else /* CONFIG_OF */ static int max77693_dt_init(struct device *dev, struct max77693_charger *chg) { + chg->fast_charge_current = DEFAULT_FAST_CHARGE_CURRENT; + return 0; } #endif /* CONFIG_OF */