From patchwork Fri Nov 16 11:01:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "(Exiting) Baolin Wang" X-Patchwork-Id: 10685907 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C52C81747 for ; Fri, 16 Nov 2018 11:02:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4AE52D111 for ; Fri, 16 Nov 2018 11:02:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A89672D128; Fri, 16 Nov 2018 11:02:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 356742D111 for ; Fri, 16 Nov 2018 11:02:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389616AbeKPVOJ (ORCPT ); Fri, 16 Nov 2018 16:14:09 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:40335 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389615AbeKPVOJ (ORCPT ); Fri, 16 Nov 2018 16:14:09 -0500 Received: by mail-pf1-f195.google.com with SMTP id x2-v6so11245949pfm.7 for ; Fri, 16 Nov 2018 03:02:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=SRjHqre43wUKPvvX7pz11akDR7cvUF9OTxM3rE3wtFs=; b=PPcUwKTDELEs2H6qRWEVBMOqPWZPT1r4mocWQTAPi2KSslFbxMaxJy+M85FunIkHxu T2ggfExjh6dD6Hq2yTWuOF2Bp/cic513KqQij3KpckKq6dSq0Ug8XCTq6ayk0ldTcc+O 1SNUkCNH92XdoWmL/81Yp9FfQFadyMciFaiN4= 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:in-reply-to :references:in-reply-to:references; bh=SRjHqre43wUKPvvX7pz11akDR7cvUF9OTxM3rE3wtFs=; b=McysvbuRqAiPr6zaEp1qPQ2iHzUb8jUMwIfCcLiHmcXEQSIlvSqh8ZW2kJrmugC5Pr qMUJggFLWmjWa7WJIz1sZRh3CT78hqmc6CKRnmkFb+T27qMGl4d0itwnXLUXQxGrTCjJ Z5lyIOtn7T8jXDGClYhEBDcwRu7Q4TgP8r82VX/Ife1DTcLB/RskXXO2WZ+AR8J/skFO mXfulfIVfR+t4OGB1HNsq6NknoA9R1mh9Zq8kPyi//OlKnZKr/L9kcJC+Ospf+aYrLZu aSVi2kdE3V5uRYUuIv7tXKHKSnUzSEVYZl6WlB/LjhzAZwQ8HZo2F6F9krsZgWi9s6C4 J8nw== X-Gm-Message-State: AGRZ1gK8nPGgd+dadPXilraMHeGgG9mwfPWvosD90CbULUX+BgJZe04f AQ8kT/NezTg2Gtw+Zlv8V215Fw== X-Google-Smtp-Source: AJdET5fbJ3eNh+INMwDji2/km92/5BoHTI6IynzkyeYkhDhXi8AZyULLU+oszrVc0fbe/zEygstphg== X-Received: by 2002:a63:d604:: with SMTP id q4mr9374494pgg.175.1542366138298; Fri, 16 Nov 2018 03:02:18 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id 202sm21268106pfy.87.2018.11.16.03.02.14 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Nov 2018 03:02:17 -0800 (PST) From: Baolin Wang To: sre@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, yuanjiang.yu@unisoc.com, baolin.wang@linaro.org, broonie@kernel.org, linus.walleij@linaro.org Subject: [PATCH 6/6] power: supply: charger-manager: Add new method to start/stop charging Date: Fri, 16 Nov 2018 19:01:13 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <4ea9eaf85d780afb190cb45da2df8ff5fd86d449.1542362262.git.baolin.wang@linaro.org> References: <4ea9eaf85d780afb190cb45da2df8ff5fd86d449.1542362262.git.baolin.wang@linaro.org> In-Reply-To: <4ea9eaf85d780afb190cb45da2df8ff5fd86d449.1542362262.git.baolin.wang@linaro.org> References: <4ea9eaf85d780afb190cb45da2df8ff5fd86d449.1542362262.git.baolin.wang@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For some chargers (such as Spreadtrum SC2731 charger), they don't use regulators to control charging, instead charging control was implemented in their drivers, so we can add some supports to start or stop charging by POWER_SUPPLY_PROP_STATUS property. Signed-off-by: Baolin Wang --- drivers/power/supply/charger-manager.c | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c index 4f28c03..d0d0b82 100644 --- a/drivers/power/supply/charger-manager.c +++ b/drivers/power/supply/charger-manager.c @@ -348,6 +348,32 @@ static bool is_polling_required(struct charger_manager *cm) return false; } +static int try_charger_enable_by_psy(struct charger_manager *cm, bool enable) +{ + struct charger_desc *desc = cm->desc; + union power_supply_propval val; + struct power_supply *psy; + int i, err; + + for (i = 0; desc->psy_charger_stat[i]; i++) { + psy = power_supply_get_by_name(desc->psy_charger_stat[i]); + if (!psy) { + dev_err(cm->dev, "Cannot find power supply \"%s\"\n", + desc->psy_charger_stat[i]); + continue; + } + + val.intval = enable; + err = power_supply_set_property(psy, POWER_SUPPLY_PROP_STATUS, + &val); + power_supply_put(psy); + if (err) + return err; + } + + return 0; +} + /** * try_charger_enable - Enable/Disable chargers altogether * @cm: the Charger Manager representing the battery. @@ -378,6 +404,10 @@ static int try_charger_enable(struct charger_manager *cm, bool enable) cm->charging_start_time = ktime_to_ms(ktime_get()); cm->charging_end_time = 0; + err = try_charger_enable_by_psy(cm, enable); + if (!err) + goto out; + for (i = 0 ; i < desc->num_charger_regulators ; i++) { if (desc->charger_regulators[i].externally_control) continue; @@ -396,6 +426,10 @@ static int try_charger_enable(struct charger_manager *cm, bool enable) cm->charging_start_time = 0; cm->charging_end_time = ktime_to_ms(ktime_get()); + err = try_charger_enable_by_psy(cm, enable); + if (!err) + goto out; + for (i = 0 ; i < desc->num_charger_regulators ; i++) { if (desc->charger_regulators[i].externally_control) continue; @@ -422,6 +456,7 @@ static int try_charger_enable(struct charger_manager *cm, bool enable) } } +out: if (!err) cm->charger_enabled = enable;