Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6335209yba; Thu, 11 Apr 2019 17:44:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFBXlz7BUSh7GRhUCLIkfhtdTVhBfkIOLq47hiJJ+0XnZIVqPpi3QecwV0D4cBPRJxvAyI X-Received: by 2002:a65:6241:: with SMTP id q1mr21705093pgv.244.1555029897901; Thu, 11 Apr 2019 17:44:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555029897; cv=none; d=google.com; s=arc-20160816; b=UwuNAtxfvXGozibMoZD5oziUrV9z3Qp8GzuY4ztlRzuqBHgiIc6RmLn4iGgGO6dS0W GZXU9aXACyY8IgQOgAthYc/OrUvya3rzBj7RIqZqD1Lwo/H6F2RdBavF40oyVO7okYdU hY/SpRCj/KGyXChPGNQ+t/bc7Ogb0Eaa5Y9HFpRY/VUMw1iL8JCJEKBj88nGq5vl+Cwn OwlhfmbgdJ8R5kIW6SgENA4xJnrBIzgQ3CwK6ClmwOVqL3xbw9QMhvLYKEhoUpZU1XaN eSACD11vn5OSJU9DJQ/ys4rskzKQlAPH60kRzKtGodUeSCNNYGkxBdA1yUFhRAv8osh4 dJBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=hldxkxWM3hSqdi6yUY+bXZzasV3q/AnL0PcDXeuAe2Y=; b=hQdpblJOUHCNkLp3pnWJI0AI965fKEvko3u4GjLwDUIddD0lJbhMrvczf84x8C0Qt2 UdaCFOcvLDWPjg433BYdfiM3SMbRfn8vEYfoxwD2xET+5toy79DYCdq7Lue2VrMEafvJ m/mqSifk3dlYs8x7rD0OvHonkvCLq6Jb6pgBLh3UJyO3BbHi5+EmvvEYbuE2NdzcD/GS Z1Jdkk8HUaDDJqwSmzox4z7ayh0v6z79uu9AnKJksW/dGmplJoYswztdSqNSOwsyn+V2 izL6aRjoPg6aL+mf/jAlqmvsxJz+YscABPSDnQu8V7WtSi2/6u7IksQRibH+kybC8II7 e4Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dIATU7AH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a20si6877128pgw.465.2019.04.11.17.44.41; Thu, 11 Apr 2019 17:44:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dIATU7AH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727353AbfDLAVA (ORCPT + 99 others); Thu, 11 Apr 2019 20:21:00 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:44196 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726629AbfDLAVA (ORCPT ); Thu, 11 Apr 2019 20:21:00 -0400 Received: by mail-io1-f68.google.com with SMTP id u12so6958718iop.11 for ; Thu, 11 Apr 2019 17:20:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hldxkxWM3hSqdi6yUY+bXZzasV3q/AnL0PcDXeuAe2Y=; b=dIATU7AHja6jdtkFkz7kGNYbqD4NaihapgrQ0auvg+Iz88lI0Agi4IK3S9nfoLg85m vN2oXpQmratUIeMm4/xK3NM0AGIVvi2TCfjQTtgWyKcIobWz00buoCZ7FNDzgmZb+zA0 eRQ3fdFK2sonqjBiCfeHbluAiaxn4xrvB+KKg= 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:mime-version :content-transfer-encoding; bh=hldxkxWM3hSqdi6yUY+bXZzasV3q/AnL0PcDXeuAe2Y=; b=BeczPYg9kk/zvqnwC/2+b9G4P22yMVRZgM9DvPaSoH+GqG5mpDGxSUGyfUBqNMrQvL 3VedYLRhJre+o64NsmE19sIdmeZVkCD1KitYRbVeQ04uavcC2eM3Od1FjwiXkNYRt5fu WJbgY2DxUZAr+KMbncA85G2+H42Zifv+HxYtaxdAMv9oTHQRMxepFlNbJheTh2KR1u1T 3aYFQ4nND4OngerjwUpmEn1XDO+vNNzvVkBCSMu+X32RAoK5+yl0fMUzGoLjdjt2U61n LloUw7dHRTt7yGrHB+4hgM/YurYrGSjErJ/ncj390VeBuA4q9aj18c2N/+hZaZ2ttcN8 6oVQ== X-Gm-Message-State: APjAAAWCYZgSvkukIiH19cID1idfkDvh5jQMCXa5+zTf1hTefhQkwGbK c3zfvYkfLvsnsYSadvE3Uu6nIQ== X-Received: by 2002:a5e:8706:: with SMTP id y6mr37334136ioj.160.1555028459509; Thu, 11 Apr 2019 17:20:59 -0700 (PDT) Received: from ncrews2.bld.corp.google.com ([2620:15c:183:200:cb43:2cd4:65f5:5c84]) by smtp.gmail.com with ESMTPSA id 64sm3552386itv.16.2019.04.11.17.20.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Apr 2019 17:20:58 -0700 (PDT) From: Nick Crews To: enric.balletbo@collabora.com, bleung@chromium.org, sre@kernel.org, linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, dlaurie@chromium.org, lamzin@google.com, bartfab@google.com, derat@google.com, groeck@google.com, dtor@google.com, sjg@chromium.org, jchwong@chromium.org, Nick Crews Subject: [PATCH v3 1/2] power_supply: Add more charge types and CHARGE_CONTROL_* properties Date: Thu, 11 Apr 2019 18:20:54 -0600 Message-Id: <20190412002055.92529-1-ncrews@chromium.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add "Standard", "Adaptive", and "Custom" modes to the charge_type property, to expand the existing "Trickle" and "Fast" modes. In addition, add POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD and POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD properties, to expand the existing CHARGE_CONTROL_* properties. I am adding them in order to support a new Chrome OS device, but these properties should be general enough that they can be used on other devices. The meaning of "Standard" is obvious, but "Adaptive" and "Custom" are more tricky: "Adaptive" means that the charge controller uses some custom algorithm to change the charge type automatically, with no configuration needed. "Custom" means that the charge controller uses the POWER_SUPPLY_PROP_CHARGE_CONTROL_* properties as configuration for some other algorithm. For example, in the use case that I am supporting, this means the battery begins charging when the percentage level drops below POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD and charging ceases when the percentage level goes above POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD. Signed-off-by: Nick Crews --- drivers/power/supply/power_supply_sysfs.c | 4 +++- include/linux/power_supply.h | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c index dce24f596160..6104a3f03d46 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -56,7 +56,7 @@ static const char * const power_supply_status_text[] = { }; static const char * const power_supply_charge_type_text[] = { - "Unknown", "N/A", "Trickle", "Fast" + "Unknown", "N/A", "Trickle", "Fast", "Standard", "Adaptive", "Custom" }; static const char * const power_supply_health_text[] = { @@ -274,6 +274,8 @@ static struct device_attribute power_supply_attrs[] = { POWER_SUPPLY_ATTR(constant_charge_voltage_max), POWER_SUPPLY_ATTR(charge_control_limit), POWER_SUPPLY_ATTR(charge_control_limit_max), + POWER_SUPPLY_ATTR(charge_control_start_threshold), + POWER_SUPPLY_ATTR(charge_control_end_threshold), POWER_SUPPLY_ATTR(input_current_limit), POWER_SUPPLY_ATTR(energy_full_design), POWER_SUPPLY_ATTR(energy_empty_design), diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 2f9c201a54d1..d59205170232 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -40,11 +40,15 @@ enum { POWER_SUPPLY_STATUS_FULL, }; +/* What algorithm is the charger using? */ enum { POWER_SUPPLY_CHARGE_TYPE_UNKNOWN = 0, POWER_SUPPLY_CHARGE_TYPE_NONE, - POWER_SUPPLY_CHARGE_TYPE_TRICKLE, - POWER_SUPPLY_CHARGE_TYPE_FAST, + POWER_SUPPLY_CHARGE_TYPE_TRICKLE, /* slow speed */ + POWER_SUPPLY_CHARGE_TYPE_FAST, /* fast speed */ + POWER_SUPPLY_CHARGE_TYPE_STANDARD, /* normal speed */ + POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE, /* dynamically adjusted speed */ + POWER_SUPPLY_CHARGE_TYPE_CUSTOM, /* use CHARGE_CONTROL_* props */ }; enum { @@ -121,6 +125,8 @@ enum power_supply_property { POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, + POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD, /* in percents! */ + POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD, /* in percents! */ POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN, -- 2.20.1