From patchwork Mon Jul 29 17:47:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Weber X-Patchwork-Id: 13745514 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 C13D0C3DA61 for ; Mon, 29 Jul 2024 17:49:41 +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:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type: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=V78HK7/KjvVm6vb5sHb4eAgphXUZC6leMWsDQBJkLes=; b=ZurCMfxuBcOPZPa9nmLjz66eCp l0aQXGBBtNmZIBfRWIdkLQeddziZaF7KBnTw6CMlPZO9NQuJZs0JPKA702IBhgp25l6yzQKFJT2Gl 0Dt6kf3ZVK3ALLbgAHgkgFp+FY4bTL6KTOBfYgl+ST2W6RVmOksX+RaJ/z7mhH/fpZIOV2EnzMVsU HJw3jYul01NupCfIOObOkPmrTk/QKx81J5RTN6/6pSufXSRr5OPmrWgg+Z1h66Q8siN3xWZjNtY+L 0S2WVgWGip9q+VoQrb1pFGxi3VBf5WjTJsI3CGt16QHAMVuGlKsvzWMG6FkdtiS/nBDXHfiEhrf31 KUyH+eFQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYUV0-0000000CFk5-1BlL; Mon, 29 Jul 2024 17:49:30 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYUTS-0000000CFDz-3jo3 for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 17:47:56 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4281faefea9so7055005e9.2 for ; Mon, 29 Jul 2024 10:47:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722275273; x=1722880073; 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=V78HK7/KjvVm6vb5sHb4eAgphXUZC6leMWsDQBJkLes=; b=NKYK2LtfxPbE8F1HWRzib0NY/t+n9GfpM6dtG+zGnmJVIejWQFOlrhEgoZ5m6Q79Su XTdD415/hwTry9TnX2KP2/n9oBn/+PQA/aO+49eQu2OGaXB2TDPa/uETDP72pKBgR5zg s3SkTcaEzlwvvu6N88ZpH8hviM9zE+Xg6joadv5kP4gkb92Rv0UShTYtylHs0mjWzhSN yOx3Rqa+8RRBBM5XaLHkvF3Jdo8dEvjTrMwuC7ZYpll8SUlqrw6n3A/4Elffy/Ufdw59 eXnfPLIHuOx/j1dTsA9BtxVUYniFUoYxIVMZjW/G9A9dPQM3vip2tNwo0SCyBFqXDRhg 2Jow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722275273; x=1722880073; 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=V78HK7/KjvVm6vb5sHb4eAgphXUZC6leMWsDQBJkLes=; b=XqGZX/AiCzNEzXP39vJftIyvnB0yCjhW4tE1ccBrWqay0F15JZDqRD+oPVxoh99F4N 3qRj/N40RP25fRRkegje77OEm9hufyOfB6mun1WSaxpxc7mkWo0hUmuXsDZ8I3LgrNpO 3uCzb6Nm7epNz1Pexi77avjhQOIMLHjkKNu9GHZJRY4qumyNuj8H9oe+eXIyM4UExasH I3dcQSADelh8oOVHY683XePXiesbBPbTuCPEhIdjCUau4KMEsISV6ZsExtZaUvBcteqM YFDlYkawNaAQXMuiUkFDI0SEI572JUIuxQK/LxG8IhClN3cZE5mDZd34j4znObU+nuTC JpnQ== X-Forwarded-Encrypted: i=1; AJvYcCVMou1Try9L3ap+ReNqG2lbqBSVG6rkAYfn9y4SaWKCR4hfW27XmmOLG2X8Zhsc3B8lIdJ43VMJxAL6a5TtLnSfcLN4kyS+QFd8sFrjKewDYdAufwI= X-Gm-Message-State: AOJu0YwEjI89+nwhFTrabij6ry6C5nxcNonCVxi81SwouryOvkCFvbts yxbVZur0ufEl/8m8kM3WFKfhvw9C3LVzJ+igXxzzdIieCRDbklEo X-Google-Smtp-Source: AGHT+IEzVP76gvohlXqS0k65XYNrnFnMn8umFHlR6ZRiwhlX5TiYE3+UjMPQEbMDs5Lg4ZBPFvjCvw== X-Received: by 2002:a05:600c:444d:b0:426:65bf:5cc2 with SMTP id 5b1f17b1804b1-42811d83c38mr55420585e9.1.1722275272600; Mon, 29 Jul 2024 10:47:52 -0700 (PDT) Received: from tablet.my.domain ([37.30.0.99]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36b367fc8a7sm12716550f8f.59.2024.07.29.10.47.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 10:47:52 -0700 (PDT) From: Artur Weber Date: Mon, 29 Jul 2024 19:47:37 +0200 Subject: [PATCH v3 03/10] power: supply: max77693: Expose input current limit and CC current properties MIME-Version: 1.0 Message-Id: <20240729-max77693-charger-extcon-v3-3-02315a6869d4@gmail.com> References: <20240729-max77693-charger-extcon-v3-0-02315a6869d4@gmail.com> In-Reply-To: <20240729-max77693-charger-extcon-v3-0-02315a6869d4@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.14.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4220; i=aweber.kernel@gmail.com; h=from:subject:message-id; bh=64p2zb/TO0sOXA+lVtMC+Y+6Z6xHMlhCGgkfq2NJimA=; b=owEBbQKS/ZANAwAKAbO7+KEToFFoAcsmYgBmp9W+FIRTZ3IhbI66s8PrQ4IXSptDHnNOxsMyV WSLOBGxHBOJAjMEAAEKAB0WIQTmYwAOrB3szWrSiQ2zu/ihE6BRaAUCZqfVvgAKCRCzu/ihE6BR aHZMD/9gIYbg0pjl+8dd0ysmLc8mn2G6E4B0A6WBIyXtqxy+os7tJFlstZV0b5U4PjpH5vc0Bhr XTn3vMyF57qrKl2l9GUdF8EuCLT3nzORYFY48FpzDF52LYbv0ILSHQbtLm9AqimfiXO1kLyDGM3 DRX5Sip3GNeTtx2c1jJ2gT5GvqhaZMbq4HcLdZoIka/dcf18KYp2SfxouD+KZMNJ1mFS46wsl+Y 1b+BW8eYRA7nk+961BeltF2Nc1R1tpvXYEIL8HfwS8mliQg4qHVc5+gd11RRtF340N3SCqINLF6 hn+4uHnwqe+o5ZNOymmWAwn1YIVdE+FykoSw2Mi+8SN/ObmY0CcEpL7klcNarlv/mDbAvE3maEy 8C7uJTZi52qFMX6U24DZvAfirl8QJQUXQT93UTNXwxiVsW/mcZ0E/WNurBi6FYP8Rwx3C9vxGS6 wHcPGV3uAAQDT0X2w0xB3eql53cMg4Tiu6iIM7f5cBO5nlCnr/j6LydNDqh89NJ6lmJNJSVDJ6u nEwWI49+yFtJP3pfPqrGyV1EIrqEGH62my6BDszcGPL1sI/1yWc0HSNqHUFW5SQH0n/qPmauXYr phj9eYaxa0v0+figTaItoGzJIV5nktYGzh2zVEqjRtfGpe7gE7Vii5biPuDKwY9I7bE7WSkOhUY k5vLYrei31ScZ1A== X-Developer-Key: i=aweber.kernel@gmail.com; a=openpgp; fpr=E663000EAC1DECCD6AD2890DB3BBF8A113A05168 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240729_104754_971515_C5D1B85C X-CRM114-Status: GOOD ( 16.28 ) 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). Add the necessary functions to retrieve the CHGIN input limit (from CHARGER regulator) and maximum fast charge current values, and expose them as power supply properties. Signed-off-by: Artur Weber --- Changes in v3: - Dropped CHARGER reg reference in favor of managing the registers directly - Changed to use CONSTANT_CHARGE_CURRENT_MAX instead of CURRENT_MAX for fast charge/CC current property Changes in v2: - Adapted to both current limits being managed in the CHARGER regulator --- drivers/power/supply/max77693_charger.c | 52 +++++++++++++++++++++++++++++++++ include/linux/mfd/max77693-private.h | 5 ++++ 2 files changed, 57 insertions(+) diff --git a/drivers/power/supply/max77693_charger.c b/drivers/power/supply/max77693_charger.c index 2001e12c9f7d..4caac142c428 100644 --- a/drivers/power/supply/max77693_charger.c +++ b/drivers/power/supply/max77693_charger.c @@ -197,12 +197,58 @@ static int max77693_get_online(struct regmap *regmap, int *val) return 0; } +/* + * There are *two* current limit registers: + * - CHGIN limit, which limits the input current from the external charger; + * - Fast charge current limit, which limits the current going to the battery. + */ + +static int max77693_get_input_current_limit(struct regmap *regmap, int *val) +{ + unsigned int data; + int ret; + + ret = regmap_read(regmap, MAX77693_CHG_REG_CHG_CNFG_09, &data); + if (ret < 0) + return ret; + + data &= CHG_CNFG_09_CHGIN_ILIM_MASK; + data >>= CHG_CNFG_09_CHGIN_ILIM_SHIFT; + + if (data <= 0x03) + /* The first four values (0x00..0x03) are 60mA */ + *val = 60000; + else + *val = data * 20000; /* 20mA steps */ + + return 0; +} + +static int max77693_get_fast_charge_current(struct regmap *regmap, int *val) +{ + unsigned int data; + int ret; + + ret = regmap_read(regmap, MAX77693_CHG_REG_CHG_CNFG_02, &data); + if (ret < 0) + return ret; + + data &= CHG_CNFG_02_CC_MASK; + data >>= CHG_CNFG_02_CC_SHIFT; + + *val = data * 33300; /* 33.3mA steps */ + + return 0; +} + static enum power_supply_property max77693_charger_props[] = { POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_CHARGE_TYPE, POWER_SUPPLY_PROP_HEALTH, POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_ONLINE, + POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, POWER_SUPPLY_PROP_MODEL_NAME, POWER_SUPPLY_PROP_MANUFACTURER, }; @@ -231,6 +277,12 @@ static int max77693_charger_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_ONLINE: ret = max77693_get_online(regmap, &val->intval); break; + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + ret = max77693_get_input_current_limit(regmap, &val->intval); + break; + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: + ret = max77693_get_fast_charge_current(regmap, &val->intval); + break; case POWER_SUPPLY_PROP_MODEL_NAME: val->strval = max77693_charger_model; break; diff --git a/include/linux/mfd/max77693-private.h b/include/linux/mfd/max77693-private.h index 54444ff2a5de..20c5e02ed9da 100644 --- a/include/linux/mfd/max77693-private.h +++ b/include/linux/mfd/max77693-private.h @@ -217,6 +217,10 @@ enum max77693_charger_battery_state { #define CHG_CNFG_01_CHGRSTRT_MASK (0x3 << CHG_CNFG_01_CHGRSTRT_SHIFT) #define CHG_CNFG_01_PQEN_MAKS BIT(CHG_CNFG_01_PQEN_SHIFT) +/* MAX77693_CHG_REG_CHG_CNFG_02 register */ +#define CHG_CNFG_02_CC_SHIFT 0 +#define CHG_CNFG_02_CC_MASK 0x3F + /* MAX77693_CHG_REG_CHG_CNFG_03 register */ #define CHG_CNFG_03_TOITH_SHIFT 0 #define CHG_CNFG_03_TOTIME_SHIFT 3 @@ -244,6 +248,7 @@ enum max77693_charger_battery_state { #define CHG_CNFG_12_VCHGINREG_MASK (0x3 << CHG_CNFG_12_VCHGINREG_SHIFT) /* MAX77693 CHG_CNFG_09 Register */ +#define CHG_CNFG_09_CHGIN_ILIM_SHIFT 0 #define CHG_CNFG_09_CHGIN_ILIM_MASK 0x7F /* MAX77693 CHG_CTRL Register */