Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4359061pxj; Wed, 12 May 2021 04:03:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNtDImtHpMGp17K+l3xJkhX2oiZqdRYRGCNZtdqeS14KjOaaFVt24KaNpuD9CDaJXp3q+3 X-Received: by 2002:a17:906:7302:: with SMTP id di2mr18252676ejc.409.1620817380590; Wed, 12 May 2021 04:03:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620817380; cv=none; d=google.com; s=arc-20160816; b=XHAWpgs16bB+L28MCCsdycJJ+lXL6UqnmzVBPgWS+8nDNU4Thl5UZ/yGxs4vq2+ndL cbYDB6F7u5nImE+YFXoZ64lMNu06Ur84UHzO6uO8YBb99w0w4SK6Un9Ga4Cq/sCGPGKZ h94JSop8ZgeiL9VQ/GBdnvX5I1dyG9RGSa9jrW1fdIKE6P4hOxu70ReSsmpwtd/kuBAl O40o8Nsi+M2Y9M3bxpKCeIwcn5VgO10pSVIFg5CUMxVv9sp+DCyy2dvzxij5w816Tayp bgtK/z5EkhCcNBN2HQBHXQMNaLE5iDzoajDm8jnBBPPFNd0vKN9ZJ9G65mVJ+OBlxDzV h9Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-hdrordr; bh=AdFT7Ba/ToD6U6lJLgx/Xp9zOZTKUZo4I5jjKMhB30I=; b=RCZlGZOppURWTN4iI91Jkr16l87jK5/XLaH+STXTuhBvIdZ0iU5RWvlNIaWCU3OR3h 9jYJQJSv5HcCzm76FIlx3pS/amELlX///LSoPLlEU6uBrxn56Csue1Xsh0Y1YVo5HjeG HzGltfCs10vG+4Bc4NdJdxyJ+h882nt/4c6ccqCizFH/KGunX9CsblAQbdh2Db7DxZGF 34/SFi/vG8sTtkCU47X3Gb+YkkGJ0BWPJWwIXDTi0mmf9L2MezXECfSvb21AkQNP9p8J N7/SQBds9RV9zzYM/VNHMZcP2Qq1adYUqw/4VgFpwJ+0fPSgy/mHf87FHchVrhcjd4rZ VvZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fi12si1768292ejb.474.2021.05.12.04.02.36; Wed, 12 May 2021 04:03:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230139AbhELLAG (ORCPT + 99 others); Wed, 12 May 2021 07:00:06 -0400 Received: from relay.uni-heidelberg.de ([129.206.100.212]:26941 "EHLO relay.uni-heidelberg.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230096AbhELLAG (ORCPT ); Wed, 12 May 2021 07:00:06 -0400 X-IPAS-Result: =?us-ascii?q?A2B8BACts5tg/1BqzoFaHQEBAQEJARIBBQUBQIFXgw1ra?= =?us-ascii?q?4RHkgGQDo0GAQEBAQEBAQEBCTkBAgQBAYZFAiU4EwIEAQEBAQMCAwEBAQYBA?= =?us-ascii?q?QYBAQEBAQYEgQSFXYZFBiMELCYQJQIfBwICFCghE4V5qQ1/M4EBiD2BISOBE?= =?us-ascii?q?CqOChCBVUSBFYNghAAlgzU2gi0EgkAHPRw1gyC7ACwHgXaBIoEpC5t8Ag4ol?= =?us-ascii?q?FaQXi2SLKZ6gWuBfDMaJIM4UBkOjlaOGEIvOAIGCgEBAwlZAQGMNQEB?= IronPort-HdrOrdr: A9a23:N765kqltNrvazo/zr13/f58lw7TpDfIj3DAbv31ZSRFFG/Fw9v rAoB1173/JYVoqMk3I+urvBEDjewK+yXcd2+B4VotKOjOGhILBFvAB0WKI+VDd8kPFmtK0gs xbAsxD4YrLfD1HZYKQ2njeL+od X-IronPort-Anti-Spam-Filtered: true Received: from lemon.iwr.uni-heidelberg.de ([129.206.106.80]) by relay.uni-heidelberg.de with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 May 2021 12:58:57 +0200 Received: from hlauer by lemon.iwr.uni-heidelberg.de with local (Exim 4.92) (envelope-from ) id 1lgmZs-000465-HE; Wed, 12 May 2021 12:58:56 +0200 Date: Wed, 12 May 2021 12:58:56 +0200 From: Hermann Lauer To: Chen-Yu Tsai Cc: Sebastian Reichel , "open list:THERMAL" , linux-kernel Subject: [PATCH v3] power: supply: axp20x_battery: implement writeable status to enable/disable battery charging Message-ID: <20210512105856.GA15727@lemon.iwr.uni-heidelberg.de> References: <20210421090354.GF19953@lemon.iwr.uni-heidelberg.de> <20210505112902.GC5302@lemon.iwr.uni-heidelberg.de> <20210510131804.GP11983@lemon.iwr.uni-heidelberg.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210510131804.GP11983@lemon.iwr.uni-heidelberg.de> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow disabling and reenabling battery charging of an axp209 PMIC through a writable status property. With the current driver code charging is always on. This works on the axp209 of Banana {Pi M1+,Pro} and should work on all AXP chips. Signed-off-by: Hermann.Lauer@uni-heidelberg.de --- v2: add fallthrough and improve commit message (thanks to Maxime and ChenYu) v3: fix fallthrough usage Thanks to ChenYu for the idea and greetings Hermann drivers/power/supply/axp20x_battery.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c --- a/drivers/power/supply/axp20x_battery.c +++ b/drivers/power/supply/axp20x_battery.c @@ -40,6 +40,7 @@ #define AXP209_FG_PERCENT GENMASK(6, 0) #define AXP22X_FG_VALID BIT(7) +#define AXP20X_CHRG_CTRL1_ENABLE BIT(7) #define AXP20X_CHRG_CTRL1_TGT_VOLT GENMASK(6, 5) #define AXP20X_CHRG_CTRL1_TGT_4_1V (0 << 5) #define AXP20X_CHRG_CTRL1_TGT_4_15V (1 << 5) @@ -468,7 +469,18 @@ case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: return axp20x_set_max_constant_charge_current(axp20x_batt, val->intval); + case POWER_SUPPLY_PROP_STATUS: + switch (val->intval) { + case POWER_SUPPLY_STATUS_CHARGING: + return regmap_update_bits(axp20x_batt->regmap, AXP20X_CHRG_CTRL1, + AXP20X_CHRG_CTRL1_ENABLE, AXP20X_CHRG_CTRL1_ENABLE); + case POWER_SUPPLY_STATUS_DISCHARGING: + case POWER_SUPPLY_STATUS_NOT_CHARGING: + return regmap_update_bits(axp20x_batt->regmap, AXP20X_CHRG_CTRL1, + AXP20X_CHRG_CTRL1_ENABLE, 0); + } + fallthrough; default: return -EINVAL; } @@ -491,7 +503,8 @@ static int axp20x_battery_prop_writeable(struct power_supply *psy, enum power_supply_property psp) { - return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN || + return psp == POWER_SUPPLY_PROP_STATUS || + psp == POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN || psp == POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN || psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT || psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX;