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: 150818 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2992882ljp; Mon, 12 Nov 2018 02:53:09 -0800 (PST) X-Google-Smtp-Source: AJdET5fUXq70Fft+Jyc0RGIzvMbrp+PtE449zF+oQNuGc/ZYYHh6mBc8AbmEEeHeYmQIq9HYigx1 X-Received: by 2002:a17:902:2bc5:: with SMTP id l63-v6mr444396plb.241.1542019989579; Mon, 12 Nov 2018 02:53:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542019989; cv=none; d=google.com; s=arc-20160816; b=ZSdF0GRlgpbpK22or1Wz84EVNPT+bN/GIf2hs4YWwKnb2wKxSFbLvn3NM/LnpWjDbv NOfGmmIcmIOZgoNhunSCmKk49pgG+jJ79HYH8nVnP79o2bj1jxfgaIrGAOnhY0R4VArW /J1UWXV08Qij5fZxug4bXLewD5x9UH/n9sQ0abRt0jVpDjt8hnFzKQRoRXje5IhoXU6A 6hVUdQtrMAu1oBAWqNRPY2EsFuZviYwt8XTUWVrJPgsUeK6TqwIuEeI6n/5L/ZjrOHP1 O98qcUcHHV8dRB0LAB+xf4XDOi9zY5s4tmFw8q3RBosTg+wrdx1macD8ijSverS5Jdo9 C8FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=qSBEaLMQTxoif/rlC/sHjfIRGMZsmwAJJs2wQVE+B5U=; b=jstjOFbKx+v2Z5uoslVf+veMoNqFDGeh7QB8xRhWxDLLr0ScyTDsW1vp8wj+Je9hW3 yVmDGkDdXMSh8+DMOzUMmG73PfWLN1m9qMD6yTaBURy50Jm4lnTarjqyqoM1X6q5/4ZW olw3t3yAlbU9aZOxKCWkE7CtLVPavMCbJKIqos2yjPcqgy+OZOtby5KAYfBMmy3SPQ2o +LdOUlFKCKRb2U/+VTHKdJXZUPYpBjjXL1arkHJMu6OGP8LhUim9LYZCLX1uwqdnA2vO dqfaQBdrfCuB0qKleJPxHvePKW2kghRk7cPGhVrqbgI7W9EfybPpZVjl+oxL5vy+1Bcm uExw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jYcr/3u0"; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o125-v6si3455665pfb.35.2018.11.12.02.53.08; Mon, 12 Nov 2018 02:53:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=@linaro.org header.s=google header.b="jYcr/3u0"; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728109AbeKLUpu (ORCPT + 11 others); 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-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 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(-) -- 1.7.9.5 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) {