From patchwork Mon Nov 12 10:52:36 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: 10678499 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 9FB821759 for ; Mon, 12 Nov 2018 10:53:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8ED5E29E25 for ; Mon, 12 Nov 2018 10:53:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 830A529EFE; Mon, 12 Nov 2018 10:53:30 +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 3049F29E25 for ; Mon, 12 Nov 2018 10:53:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729212AbeKLUqL (ORCPT ); Mon, 12 Nov 2018 15:46:11 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:46334 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728302AbeKLUpx (ORCPT ); Mon, 12 Nov 2018 15:45:53 -0500 Received: by mail-pl1-f196.google.com with SMTP id t13so1211918ply.13 for ; Mon, 12 Nov 2018 02:53:11 -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=HOXqfssWr+GA/FOx7jvb56dSFIWUhT4eEupIEdpFDGI=; b=fXAOav+mraP+N9dy7FR2kkWZYlok0XTd5+E2fxqdoMQvs77zlJ9gRC6qQ9jeo7Q5U2 7MuqGCZ5JB3AIGJBYk5UBxA7OZv3rKkogdtwNc3kHUzZyAzFcIMxFjtdbC8kteEw9NBI yKpfd7rWYpxyaacoVwpPdteKIPC1RHXcFPB6M= 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=HOXqfssWr+GA/FOx7jvb56dSFIWUhT4eEupIEdpFDGI=; b=m8LrDFROutuwbmuvCtncDIXWgHrBUS8Cn9T+u6sHACTeJeAA4Zyl2UGT6sJ/BgWR8V rtv6IkZo0nOKWeObon1WNKxQ6aAMDWb0T1vPztTvnU/pPLfaVWFpkGsZjI6or1QW6xZK wx24IudtjtTFOHKm8cQLfqLXtim0ZmNFEXPhbKeUYLKlsfl0V3Io0muLClWoCIakoiuy FW9+gmzz9a/iCGrnNN8btUx/8/yJ2fzllXNnxdu9XaCdKe4XryLFD2T0FxIJhY/n0iWr ZahdveT0MiXelkqyhTwzQff7YdZ93Bs1KNDRKuzap0o8XhJn5TJuPp1V4uICiojJtrPc vOEQ== X-Gm-Message-State: AGRZ1gJdjmO4Jr9d7Co8Lysg/mOQteCONfE402Fz2QnsHZ23EyiUS4yO cimbu7HTjoPcKvOYHp6hOCAqZg== X-Google-Smtp-Source: AJdET5dLTa5+Mx7PHRpgLQqOLJdRyHOhk6Zws1uTzN0sgcEU8pBmO+WVn69Ev5EIf3pgktk0Bkt1Cg== X-Received: by 2002:a17:902:622:: with SMTP id 31-v6mr459108plg.310.1542019990064; Mon, 12 Nov 2018 02:53:10 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id 186-v6sm17545705pfe.39.2018.11.12.02.53.07 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Nov 2018 02:53:09 -0800 (PST) From: Baolin Wang To: sre@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, yuanjiang.yu@unisoc.com, baolin.wang@linaro.org, broonie@kernel.org Subject: [PATCH 2/4] power: supply: sc2731_charger: Add charger status detection Date: Mon, 12 Nov 2018 18:52:36 +0800 Message-Id: <7fa4e3191a6be72b5a90d0ee73b70457a699f9bd.1542019800.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <5d096dec07f6808a70edcfaad6e8f77039f21a9b.1542019800.git.baolin.wang@linaro.org> References: <5d096dec07f6808a70edcfaad6e8f77039f21a9b.1542019800.git.baolin.wang@linaro.org> In-Reply-To: <5d096dec07f6808a70edcfaad6e8f77039f21a9b.1542019800.git.baolin.wang@linaro.org> References: <5d096dec07f6808a70edcfaad6e8f77039f21a9b.1542019800.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 The USB charger status can be notified before the charger driver registers the USB phy notifier, so we should check the charger status in probe() in case we missed the USB charger notification. Signed-off-by: Baolin Wang --- drivers/power/supply/sc2731_charger.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/power/supply/sc2731_charger.c b/drivers/power/supply/sc2731_charger.c index 393ba98..a012d6c 100644 --- a/drivers/power/supply/sc2731_charger.c +++ b/drivers/power/supply/sc2731_charger.c @@ -432,6 +432,24 @@ static int sc2731_charger_hw_init(struct sc2731_charger_info *info) return ret; } +static void sc2731_charger_detect_status(struct sc2731_charger_info *info) +{ + unsigned int min, max; + + /* + * If the USB charger status has been USB_CHARGER_PRESENT before + * registering the notifier, we should start to charge with getting + * the charge current. + */ + if (info->usb_phy->chg_state != USB_CHARGER_PRESENT) + return; + + usb_phy_get_charger_current(info->usb_phy, &min, &max); + info->limit = min; + + schedule_work(&info->work); +} + static int sc2731_charger_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; @@ -486,6 +504,8 @@ static int sc2731_charger_probe(struct platform_device *pdev) return ret; } + sc2731_charger_detect_status(info); + return 0; }