From patchwork Mon Jul 29 17:47:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Weber X-Patchwork-Id: 13745511 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 2EA5AC3DA61 for ; Mon, 29 Jul 2024 17:48:29 +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: Content-Transfer-Encoding:Content-Type:MIME-Version:Message-Id:Date:Subject: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Pnyl1Fm6dnpc6MtOd4c54WB7CEXHNdORrEgIOaBPmMw=; b=Jq3SbSt+m3GLgR v19LOsHn6mWCJw7S9555SxB9HtOLB5DLbhA87EcNP1ymxXg6lHK5oe+LvFGsaLCPtM3NBWDBuQ19a roS2QH+S4qqyNyavLe/ocBVr6p9wOyoEx4XwOLHDwoZBpMsONwjYd/ZI9yAwB35xhON6DaWWnpvTw o4J8u30WU058gshcA1+PO6t2mKIyFrG/1WTan2nthyxBRg0b1SRi/Pmuqq4NFQveibBp1+WwLkGxb YrRvme3eYksoS8+LyQZ8QFq4UPjCyPLm49CjRbfDdSbvqQsfMYaefytv7wibcAj8prcV7YhfW8/f1 1y7Ei6VrKHxZvlzQkZ3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYUTo-0000000CFLa-3RBH; Mon, 29 Jul 2024 17:48:16 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYUTN-0000000CFCY-14Qt for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 17:47:51 +0000 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-36858357bb7so1579721f8f.2 for ; Mon, 29 Jul 2024 10:47:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722275267; x=1722880067; darn=lists.infradead.org; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:from:to:cc:subject:date:message-id:reply-to; bh=Pnyl1Fm6dnpc6MtOd4c54WB7CEXHNdORrEgIOaBPmMw=; b=eOAgkopCzrLRgBGfLaWud1SfX83PxBuPHGfAJ3Lcc2qnqStxo5XIT/04m/sGWlZqVb 2iMHZFaITP1jnRsjWWw9FVZeIAz/uVR4tJQ6QL8EznBzxgCK9qAHj6gjW50cGqFW1JaI A8ILYoLPv6k8rZn4sgF/RngdkTrWdoT0vLBqWB4Ahvo3hUCfb68qiuRsl3qgL3Oz1CGs OnH5UbQruq0LwJCuRTxYlP3Vm2VGgQsxAfFGwWOM3hQLVMlonmqlz0qFVVgD0i1IXWvI hb8QMajCft21nmCXnNU2Ew9ur26MnmozDlgrVqY9AgWYn4Ay0VTyyQVMc697wCmjdIoS AuzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722275267; x=1722880067; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Pnyl1Fm6dnpc6MtOd4c54WB7CEXHNdORrEgIOaBPmMw=; b=tWO7PjrqCF8ZLX9t2TiQ9AN8bqlh0KVZqR3SqmxGqgDNU3pJBEftqCkHLhOa4t9BXb 4QNHC8+5fYQtIjnMujXEA7gzI29D0+0PXh6yUTtNzAmv1RbnKnzFQj7q1i1NZpGbMKNx YWbn/xtsHNtaRKW6N2hL6JJEDvnlXM7BdQhyisY6iYlvBES7sEY7z7v5J5cO9Y695HxB SN7tcSMsArWx4I1nuLhYWcM6YMNXQmQRqlZBgsELsICvuHGoJJsRcbFcHBbv/wpTW9bM tYVyc1eK8FT7fp+L0AM8TuWvBGk0FMwpKfdxVQ5iTjSy9IBiC/Sh/bMKKXo4dri30iqT DqQw== X-Forwarded-Encrypted: i=1; AJvYcCVOxKisFj1quZo11wbXkoRBUH+RbiwNfqDb19HzmOEcAw3nmlnpFFSvLullpXMWQj+iGSfqLtqW0RXDwVxSpjUtSCbKRxxES4WnB+GgIIXQTZVoLrI= X-Gm-Message-State: AOJu0YxwRY1+rYQVNIZg+6F+Dr68CZazo/ZlFQVT6kYyYwaUkKn6UsEV /ppexAFqUNAMeFFT26Zvc9qgWKWFwUHmwh/6v1CpbokSrUVQVywOvzBmdw== X-Google-Smtp-Source: AGHT+IHLvm7BPEtc9W0QLw+jMFn9fEXLREx620qqvb1/GY1x18fNukgK4rt67upiSgT2nwwCGAPipg== X-Received: by 2002:adf:f5cd:0:b0:367:8a87:ada2 with SMTP id ffacd0b85a97d-36b5cefd2fdmr5004948f8f.26.1722275266424; Mon, 29 Jul 2024 10:47:46 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 10:47:45 -0700 (PDT) From: Artur Weber Subject: [PATCH v3 00/10] power: supply: max77693: Toggle charging/OTG based on extcon status Date: Mon, 29 Jul 2024 19:47:34 +0200 Message-Id: <20240729-max77693-charger-extcon-v3-0-02315a6869d4@gmail.com> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIALbVp2YC/3XOyw6CMBAF0F8hXVvTh9jiyv8wLvqYQhOhpCUNh vDvFmKiG5Z3JvfMLChB9JDQrVpQhOyTD0MJ/FQh06mhBextyYgRdiE1q3GvZiGuDcdlHVuIGOb JhAE3oLXQykpuAJX2GMH5eZcfz5I7n6YQ3/uhTLfp1+Tk0MwUE2wNUw3U2jpO7m2v/OtsQo82M 7OfI+jxb5kVh0gundOaSsP/nXVdP5ss+r0GAQAA 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 , Krzysztof Kozlowski X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4799; i=aweber.kernel@gmail.com; h=from:subject:message-id; bh=ZBeCVq76s1YcWohvGVE5wNLt+NvZAu6jcfawXYj2BqM=; b=owEBbQKS/ZANAwAKAbO7+KEToFFoAcsmYgBmp9W98Mdnl67vI2rkeJCCu+vhxYNNREfuNvBtU n3iwxgaY3mJAjMEAAEKAB0WIQTmYwAOrB3szWrSiQ2zu/ihE6BRaAUCZqfVvQAKCRCzu/ihE6BR aJJ7EACYEfWhfKcmtoLfb+s8cjo4YaBDhaY44DbG+hWpObrevEb3Cpe/nVxC4tyH7FWqVWjWk5k 3+CDF3t38H355pscftMTQTs23cosdgkh2ZfJsb81CitzFJKCehwXWiVbY2fbP+w5dqmn8KsI5wi eKSuI5VAT8RQNkGyIC+jawaqIOWUqtTZKHXwT8xWudcJHmZkvp+NYZoyfMvWAfiN/Po+Vy5wjmZ kAOnWBvg2Y+qhcIfTlEis97pM0XcY74ADiN6iuoulT5J76WGt3qDXh44WXNNYH7KveVixrhb8Nd xGYkDx7fAMoGA8OxroyZyhs9D8cp3p+wIhEyqTKKAzdbtRD7nD1Obr9mJT5mRgFZlTIInIChzw8 qtvaxMPvJxYs9w2ncs3miYwde4cVO8AdpXn4lhlehk0w+Jvbt+R3lphytX9eWyk/j4siTeKCcuh 0QdyjozRefV0okQk5hHr7ZlHa4KoNatXq9Xz/iUt6wRhRZWhrzsGHsLabTwfbGbQfuyEdoJcU28 v8dFlpAjksS1PRcPuw4V0TSbvBD5WfEzpc3PR2W/Ir5VzzLHam4eFoC7V55hRfRcTcN8FvQB4dy TveJfBzV3bPIvEjwMuva42sQi79JkC57dgtWiATjUOapf7jus1P9NlSv/lU9EpL1bDA2Ja/kjcu b/FUadLBbleBGoQ== 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_104749_335366_CC316AD9 X-CRM114-Status: GOOD ( 20.60 ) 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 This patchset does the following: - Add CURRENT_MAX and INPUT_CURRENT_MAX power supply properties to expose the "fast charge current" (maximum current from charger to battery) and "CHGIN input current limit" (maximum current from external supply to charger). - Add functions for toggling charging and OTG modes. - Add an extcon-based handler that enables charging or OTG depending on the cable type plugged in. The extcon device to use for cable detection can be specified in the device tree, and is entirely optional. The extcon listener implementation is inspired by the rt5033 charger driver (commit 8242336dc8a8 ("power: supply: rt5033_charger: Add cable detection and USB OTG supply")). Signed-off-by: Artur Weber Tested-by: Henrik Grimler --- v3 no longer uses the CHARGER regulator to manage the power status, and that's for two reasons: - Regulator enable/disable behavior was interfering with how the power supply driver worked (we occasionally got "unbalanced disables" errors when switching charging state, despite checking for the regulator status with regulator_is_enabled() - the CHARGER reg would report as enabled despite the enable count being 0). This broke OTG insertion if the OTG cable was plugged in first, and sometimes caused warnings on unsuspend. - Changing the charging values directly in the power supply driver is less opaque and lets us avoid bringing in a dependency on regulators. It also splits the current limits back into two properties: INPUT_CURRENT_LIMIT and CONSTANT_CHARGE_CURRENT_MAX. Again, there are two reasons for this split: - They are two separate current controls, one for USB->charger and one for charger->battery, and they have different limits (0-2.1A for CC vs 60mA-2.58A for input). Given that the power supply core has the properties for both values separately, it's more logical to present them as such. - It's safer to keep these separate; CONSTANT_CHARGE_CURRENT_MAX is pretty explicitly only set *once* - at probe time with a safe value specified in the DT. This way, INPUT_CURRENT_LIMIT is safer to modify since in the event of an invalid value the CC current will hold back the extra current thus preventing damage to the battery. The latter is relevant as I'm working on a follow-up patchset that allows for controlling the charging parameters using power supply properties/sysfs properties rather than the CHARGER regulator. Note that the CHARGER regulator gets disabled automatically if it's not used, which will disable charging if it was auto-enabled by the extcon code. This can be worked around by re-attaching the cable, or more properly by removing the CHARGER regulator from DT for devices that use the extcon-based charger management, as has been done in the Galaxy Tab 3 8.0 DTSI. See v1 for old description: https://lore.kernel.org/r/20240530-max77693-charger-extcon-v1-0-dc2a9e5bdf30@gmail.com --- Changes in v3: - Drop uses of CHARGER regulator, manage registers directly in power supply driver instead - Link to v2: https://lore.kernel.org/r/20240715-max77693-charger-extcon-v2-0-0838ffbb18c3@gmail.com Changes in v2: - Changed to use monitored-battery for charge current value - Both current limit variables are now set by the CHARGER regulator - Link to v1: https://lore.kernel.org/r/20240530-max77693-charger-extcon-v1-0-dc2a9e5bdf30@gmail.com --- Artur Weber (10): dt-bindings: power: supply: max77693: Add monitored-battery property dt-bindings: power: supply: max77693: Add maxim,usb-connector property power: supply: max77693: Expose input current limit and CC current properties power: supply: max77693: Set charge current limits during init power: supply: max77693: Add USB extcon detection for enabling charging power: supply: max77693: Add support for detecting and enabling OTG power: supply: max77693: Set up charge/input current according to cable type ARM: dts: samsung: exynos4212-tab3: Add battery node with charge current value ARM: dts: samsung: exynos4212-tab3: Add USB connector node ARM: dts: exynos4212-tab3: Drop CHARGER regulator .../bindings/power/supply/maxim,max77693.yaml | 15 + arch/arm/boot/dts/samsung/exynos4212-tab3.dtsi | 22 +- drivers/power/supply/Kconfig | 1 + drivers/power/supply/max77693_charger.c | 302 ++++++++++++++++++++- include/linux/mfd/max77693-private.h | 12 + 5 files changed, 337 insertions(+), 15 deletions(-) --- base-commit: 0c3836482481200ead7b416ca80c68a29cfdaabd change-id: 20240525-max77693-charger-extcon-9ebb7bad83ce Best regards,