From patchwork Mon Nov 12 10:52:35 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: 10678493 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 9F21013B5 for ; Mon, 12 Nov 2018 10:53:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AF3D29E25 for ; Mon, 12 Nov 2018 10:53:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C7A329EFE; Mon, 12 Nov 2018 10:53:09 +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 20A7D29E25 for ; Mon, 12 Nov 2018 10:53:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728109AbeKLUpu (ORCPT ); Mon, 12 Nov 2018 15:45:50 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:45946 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728054AbeKLUpu (ORCPT ); Mon, 12 Nov 2018 15:45:50 -0500 Received: by mail-pl1-f195.google.com with SMTP id r3-v6so3438592pls.12 for ; Mon, 12 Nov 2018 02:53:07 -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; bh=qSBEaLMQTxoif/rlC/sHjfIRGMZsmwAJJs2wQVE+B5U=; b=jYcr/3u07sWgDbtZaVIrHOPZfwRdtlpfIZM2SabGLo+mGy7P+dEEfHMDmySwtUP/UZ jpcPrA/+nb1fFWwA1fn0PepmONaa+iPuplJivD/hWDOSRDphPkH8iMDS7sWLMCPkokR0 hHUHxrfWsiKTsKrXMdRpUcIogFNcso6MJ6tY4= 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; bh=qSBEaLMQTxoif/rlC/sHjfIRGMZsmwAJJs2wQVE+B5U=; b=DS1r8ZXfK632cuyc9gzkSXxxX51maQL3w0ACJKyaw1Ww424hDQWXpGeuNwQ72SFGqX IZg9e5O75Vgg+94YR2rxB6ynNqLxFQchaqbDXsZwK3n++NGRLJoYhOy+FH3y8974jc6z NlfsigFGXNtbgTJbkdGwV7KD4DuKEzSGtkiUSqEljfJrj+L/1iy+g0SxkMs0Ja+ciUY3 Y2M4uqdE2snAKXWFpSyc55kKe/p7RMvO17wrG+tl+OgAXEBMryZSb1vVffKmg+kvquOu 8zsBnw81cmoiGZ28lxIRWkgenS1FMscE4qW9ElEeO9ipvOZF8lbYlHuX/va965emCa7w TJKQ== X-Gm-Message-State: AGRZ1gLYXVMHjyY3CnDoXLFeUUhB79Qy49qN8zb5Y6OsoxCQ3zZZ8iFA jw0Wv1Yxr+ruiK/Lx4xfgpEO2g== X-Google-Smtp-Source: AJdET5dXGrxqHznxKj+Ur9lD39xH3tO6eMJUOYpQotI0eBtdGZbm378+O9zGlFYSzYa0gagpVuKUTA== X-Received: by 2002:a17:902:1122:: with SMTP id d31-v6mr439172pla.259.1542019987406; Mon, 12 Nov 2018 02:53:07 -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.04 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Nov 2018 02:53:06 -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 1/4] power: supply: sc2731_charger: Add one work to charge/discharge Date: Mon, 12 Nov 2018 18:52:35 +0800 Message-Id: <5d096dec07f6808a70edcfaad6e8f77039f21a9b.1542019800.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 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 Since the USB notifier context is atomic, we can not start or stop charging in atomic context. Thus this patch adds one work to help to charge or discharge. Signed-off-by: Baolin Wang --- drivers/power/supply/sc2731_charger.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/drivers/power/supply/sc2731_charger.c b/drivers/power/supply/sc2731_charger.c index 525a820..393ba98 100644 --- a/drivers/power/supply/sc2731_charger.c +++ b/drivers/power/supply/sc2731_charger.c @@ -57,9 +57,11 @@ struct sc2731_charger_info { struct usb_phy *usb_phy; struct notifier_block usb_notify; struct power_supply *psy_usb; + struct work_struct work; struct mutex lock; bool charging; u32 base; + u32 limit; }; static void sc2731_charger_stop_charge(struct sc2731_charger_info *info) @@ -318,22 +320,21 @@ static int sc2731_charger_property_is_writeable(struct power_supply *psy, .property_is_writeable = sc2731_charger_property_is_writeable, }; -static int sc2731_charger_usb_change(struct notifier_block *nb, - unsigned long limit, void *data) +static void sc2731_charger_work(struct work_struct *data) { struct sc2731_charger_info *info = - container_of(nb, struct sc2731_charger_info, usb_notify); - int ret = 0; + container_of(data, struct sc2731_charger_info, work); + int ret; mutex_lock(&info->lock); - if (limit > 0) { + if (info->limit > 0) { /* set current limitation and start to charge */ - ret = sc2731_charger_set_current_limit(info, limit); + ret = sc2731_charger_set_current_limit(info, info->limit); if (ret) goto out; - ret = sc2731_charger_set_current(info, limit); + ret = sc2731_charger_set_current(info, info->limit); if (ret) goto out; @@ -350,7 +351,19 @@ static int sc2731_charger_usb_change(struct notifier_block *nb, out: mutex_unlock(&info->lock); - return ret; +} + +static int sc2731_charger_usb_change(struct notifier_block *nb, + unsigned long limit, void *data) +{ + struct sc2731_charger_info *info = + container_of(nb, struct sc2731_charger_info, usb_notify); + + info->limit = limit; + + schedule_work(&info->work); + + return NOTIFY_OK; } static int sc2731_charger_hw_init(struct sc2731_charger_info *info) @@ -432,6 +445,7 @@ static int sc2731_charger_probe(struct platform_device *pdev) mutex_init(&info->lock); info->dev = &pdev->dev; + INIT_WORK(&info->work, sc2731_charger_work); info->regmap = dev_get_regmap(pdev->dev.parent, NULL); if (!info->regmap) {