From patchwork Thu Dec 7 05:26:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 120919 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp7939984qgn; Wed, 6 Dec 2017 21:27:10 -0800 (PST) X-Google-Smtp-Source: AGs4zMb0/b8x6KG2U3yl/y9PkmR+OLdsZ+SwUcmoiYmfZWJJUhslT2B7vHNTBE/4w7xnmZG6bGWD X-Received: by 10.84.174.131 with SMTP id r3mr24843094plb.358.1512624430669; Wed, 06 Dec 2017 21:27:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512624430; cv=none; d=google.com; s=arc-20160816; b=UkOLVsPvyF1eoYpVzRPP5bZ0yRwWTpSPVe1HPMJvA7wj9BHadgOkSCAs/fbRMFJgVj Fzh8N7m7OScaIUUAZM8anGWX9CqaYNqwkj4wlGMbUDE7bARU12HhRifO7KuFQQgIIPcE M3ySqPlvcyAyU7OtxnjQkz6T83759Cr7jETAwHAN3As1iwDGLN0f9T2+ttvgu2+oKbGZ 9DYqg/tO7j1YCooQHwEkQFpOLfRO9yH1m0/eBpIErdkFBCfHQMpHeU4z8PRAw2RyLb5P kwE/cpPO6vj5YIg+fEJn2EdkUzJsGeLzTAlaRAPa5vKe6kqQzDKgsPUXq25A8I//hseH 3k6w== 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:arc-authentication-results; bh=zoOq0YuiUeZbEQ9xG/9JLA+788+mo1PiBt9ZYojFhPA=; b=YULwfqkzYVvfueXVm12kLEhehwbByMTn42y6iMAO6pHT6/sf6gDt8QjRAsQHh+rjN3 vlI9NZcoC2eDCJCynw3CjCqoK7c/IUbZ08t+cw9oLTPpNyox8XuYDfzAcq06ireqEkGj gmCCOe7vmUaeX2ksxs7AnomJm4FwmvliqycAJMTrKRmqyHoXd/3IEoUEgYFCdsTloWRI lQy3pBytGKxQvevrL596Weo479cFF8YFsDT1M6ZsHLcI7hBlV3xDC5tg3T9FEVlPRv6E DE3Cn/xK/kuy/OeMjrsf/BuLpweYcJddXAOwZNMPcQfTo9GGoXkJCMYSYZnZ+BwKIGBz Yvhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ecrhlfh7; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1si3040000pgu.390.2017.12.06.21.27.10; Wed, 06 Dec 2017 21:27:10 -0800 (PST) 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=@linaro.org header.s=google header.b=ecrhlfh7; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750981AbdLGF1I (ORCPT + 20 others); Thu, 7 Dec 2017 00:27:08 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:40598 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750744AbdLGF1H (ORCPT ); Thu, 7 Dec 2017 00:27:07 -0500 Received: by mail-pf0-f196.google.com with SMTP id v26so3870190pfl.7 for ; Wed, 06 Dec 2017 21:27:06 -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=zoOq0YuiUeZbEQ9xG/9JLA+788+mo1PiBt9ZYojFhPA=; b=ecrhlfh7IaNaD7F8Phisg+1FjlejoGIqSZoX+SUwG24rVvojX7UM3wPu5ATE1+koaY t/Jn26aDvG5b6SGUV6KLNdSwMtiGZk5UGMl45NuJNiBIKbHH2djd6/o8FVUezGWUtFlX sRsMUIqJHYcYV9nXo4cHLvBmVdDqmsqi3RAsE= 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=zoOq0YuiUeZbEQ9xG/9JLA+788+mo1PiBt9ZYojFhPA=; b=guHDM7J1nC0TJfDrWkMInPorUOhaOuUgBiQ9G3ED9XyEskQde+P9BelEY+6hs+SoBF MWRpAsmBPrjQjFShJfmdtPH5RzAEcRBKZ4MgTqjG2KPtgcYvYc0cRzJ3cZowEFwnyUnO +07UB7PnvQ/gTQ0TItREpgvJwVK7qtDpOmRGowQdEobaIjLmQGpfoTTSc1/V0mm683i8 7pVWA27zqivu5B3+4Lh8n9xJiynqCBCL7Bt0/5a+a99S0MTTpzQVPUH4EgfFcWI2JvTu /Qq1Nc1npz+vfvmntJ562H633nNntgKNFkpWCuhNY+SjVQ3EHl9YaCxwTb6HsUVTX3ki TZBw== X-Gm-Message-State: AKGB3mLhUUAo3/hpz9MJgBTYiV/nuBhcW7azPc6qluP2gJo/lFDlyUE8 /KW5bXpZ61xXPDH02fLdoqQDNA== X-Received: by 10.84.252.19 with SMTP id x19mr1149099pll.237.1512624426429; Wed, 06 Dec 2017 21:27:06 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id p72sm7901948pfa.84.2017.12.06.21.27.00 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Dec 2017 21:27:05 -0800 (PST) From: Baolin Wang To: balbi@kernel.org Cc: gregkh@linuxfoundation.org, broonie@kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [PATCH] usb: phy: Factor out the usb charger initialization Date: Thu, 7 Dec 2017 13:26:14 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Factor out the guts of usb charger initialization into usb_charger_init() function, to make the usb_add_extcon() only do the extcon related things. Meanwhile we also should initialize the USB charger before registering the extcon device, in case the extcon notification was issued earlier than usb charger initialization. Signed-off-by: Baolin Wang --- drivers/usb/phy/phy.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) -- 1.7.9.5 diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index f97cb47..bceb2c9 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c @@ -323,6 +323,14 @@ static int devm_usb_phy_match(struct device *dev, void *res, void *match_data) return *phy == match_data; } +static void usb_charger_init(struct usb_phy *usb_phy) +{ + usb_phy->chg_type = UNKNOWN_TYPE; + usb_phy->chg_state = USB_CHARGER_DEFAULT; + usb_phy_set_default_current(usb_phy); + INIT_WORK(&usb_phy->chg_work, usb_phy_notify_charger_work); +} + static int usb_add_extcon(struct usb_phy *x) { int ret; @@ -406,10 +414,6 @@ static int usb_add_extcon(struct usb_phy *x) } } - usb_phy_set_default_current(x); - INIT_WORK(&x->chg_work, usb_phy_notify_charger_work); - x->chg_type = UNKNOWN_TYPE; - x->chg_state = USB_CHARGER_DEFAULT; if (x->type_nb.notifier_call) __usb_phy_get_charger_type(x); @@ -704,6 +708,7 @@ int usb_add_phy(struct usb_phy *x, enum usb_phy_type type) return -EINVAL; } + usb_charger_init(x); ret = usb_add_extcon(x); if (ret) return ret; @@ -749,6 +754,7 @@ int usb_add_phy_dev(struct usb_phy *x) return -EINVAL; } + usb_charger_init(x); ret = usb_add_extcon(x); if (ret) return ret;