From patchwork Thu Mar 23 05:54:57 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: 95885 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp618763qgd; Thu, 23 Mar 2017 00:45:34 -0700 (PDT) X-Received: by 10.98.19.156 with SMTP id 28mr1367217pft.208.1490255133926; Thu, 23 Mar 2017 00:45:33 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f22si4607641plk.264.2017.03.23.00.45.33; Thu, 23 Mar 2017 00:45:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752040AbdCWHpT (ORCPT + 4 others); Thu, 23 Mar 2017 03:45:19 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:32821 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751506AbdCWHo7 (ORCPT ); Thu, 23 Mar 2017 03:44:59 -0400 Received: by mail-pf0-f180.google.com with SMTP id o190so20389202pfo.0 for ; Thu, 23 Mar 2017 00:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=/7xaa3USvw/EnKeh5fiKpbAhKJcy7UbJ9vlZieA2p9s=; b=PIk2XBbmRlf6HCpj4y0M7b2v1x3wSMcsWlg+sH06LjRX3w9xvjFNpM6yP8nIWe9nTi +OGqmx/kH5NXy9HQt2WrEZy6kP5ELa5HJvRUnajo59uJvVdZy4aBHT47B5mQVjQIFZMU 382V//KQgjNtDc/e46QqJCNNY7Q7KMB0bEcWA= 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=/7xaa3USvw/EnKeh5fiKpbAhKJcy7UbJ9vlZieA2p9s=; b=SKEIPcb1vAaQ49auclFEEYgXWWM7OifMpPOiwiKV98OG0x8BU0YnunREdOp4pGn5Og Wn0cCxVcFAG/cwr+LZKI9Z/9EDHOg/pM0ef/5CKm8LKiBlsMp7Ao8lp1QGZvCDB9LADm 3aB0KnDDDRtjKBD5jCqrcI3OgbVfoBt3K/zgIbsjsJvyizNFvGvvtHyUynMnZZeyjk93 Ru8AHIRWfqhoMfiywjsgWN3z0zpd9uuUY3CvAm6XOyhmGMIjl0TpgE7oamNl+mZKfgQh X9eXSJpBMW9yrokzmCarvsJBZHlZg2AGFTDBPumU+zdbX833gRYYIHF/7G5LYuLH+SL4 UqBg== X-Gm-Message-State: AFeK/H0UuUFWAaLWxZlrTANZMgY8ck06ByxJVZSqszT81rvlF1fbwIwsfpKpm2IeGvX5HkBI X-Received: by 10.98.216.202 with SMTP id e193mr965812pfg.80.1490248520681; Wed, 22 Mar 2017 22:55:20 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id t66sm7282467pfk.53.2017.03.22.22.55.17 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 22:55:20 -0700 (PDT) From: Baolin Wang To: balbi@kernel.org, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, neilb@suse.com, jun.li@nxp.com, peter.chen@freescale.com, broonie@kernel.org, baolin.wang@linaro.org Subject: [PATCH v2 1/2] usb: phy: Introduce one extcon device into usb phy Date: Thu, 23 Mar 2017 13:54:57 +0800 Message-Id: <0b16763df04e197fb5b3c21b19799280d3bce275.1490248054.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Usually usb phy need register one extcon device to get the connection notifications. It will remove some duplicate code if the extcon device is registered using common code instead of each phy driver having its own related extcon APIs. So we add one pointer of extcon device into usb phy structure, and some other helper functions to register extcon. Suggested-by: NeilBrown Signed-off-by: Baolin Wang --- Changes since v1: - Fix build errors with random config. --- drivers/usb/phy/Kconfig | 6 +++--- drivers/usb/phy/phy.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/phy.h | 6 ++++++ 3 files changed, 53 insertions(+), 3 deletions(-) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index 61cef75..c9c61a8 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -4,6 +4,7 @@ menu "USB Physical Layer drivers" config USB_PHY + select EXTCON def_bool n # @@ -116,7 +117,7 @@ config OMAP_OTG config TAHVO_USB tristate "Tahvo USB transceiver driver" - depends on MFD_RETU && EXTCON + depends on MFD_RETU depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' select USB_PHY help @@ -148,7 +149,6 @@ config USB_MSM_OTG depends on (USB || USB_GADGET) && (ARCH_QCOM || COMPILE_TEST) depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' depends on RESET_CONTROLLER - depends on EXTCON select USB_PHY help Enable this to support the USB OTG transceiver on Qualcomm chips. It @@ -162,7 +162,7 @@ config USB_MSM_OTG config USB_QCOM_8X16_PHY tristate "Qualcomm APQ8016/MSM8916 on-chip USB PHY controller support" depends on ARCH_QCOM || COMPILE_TEST - depends on RESET_CONTROLLER && EXTCON + depends on RESET_CONTROLLER select USB_PHY select USB_ULPI_VIEWPORT help diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index 98f75d2..baa8b18 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c @@ -100,6 +100,41 @@ static int devm_usb_phy_match(struct device *dev, void *res, void *match_data) return *phy == match_data; } +static int usb_add_extcon(struct usb_phy *x) +{ + int ret; + + if (of_property_read_bool(x->dev->of_node, "extcon")) { + x->edev = extcon_get_edev_by_phandle(x->dev, 0); + if (IS_ERR(x->edev)) + return PTR_ERR(x->edev); + + if (x->vbus_nb.notifier_call) { + ret = devm_extcon_register_notifier(x->dev, x->edev, + EXTCON_USB, + &x->vbus_nb); + if (ret < 0) { + dev_err(x->dev, + "register VBUS notifier failed\n"); + return ret; + } + } + + if (x->id_nb.notifier_call) { + ret = devm_extcon_register_notifier(x->dev, x->edev, + EXTCON_USB_HOST, + &x->id_nb); + if (ret < 0) { + dev_err(x->dev, + "register ID notifier failed\n"); + return ret; + } + } + } + + return 0; +} + /** * devm_usb_get_phy - find the USB PHY * @dev - device that requests this phy @@ -388,6 +423,10 @@ int usb_add_phy(struct usb_phy *x, enum usb_phy_type type) return -EINVAL; } + ret = usb_add_extcon(x); + if (ret) + return ret; + ATOMIC_INIT_NOTIFIER_HEAD(&x->notifier); spin_lock_irqsave(&phy_lock, flags); @@ -422,12 +461,17 @@ int usb_add_phy_dev(struct usb_phy *x) { struct usb_phy_bind *phy_bind; unsigned long flags; + int ret; if (!x->dev) { dev_err(x->dev, "no device provided for PHY\n"); return -EINVAL; } + ret = usb_add_extcon(x); + if (ret) + return ret; + ATOMIC_INIT_NOTIFIER_HEAD(&x->notifier); spin_lock_irqsave(&phy_lock, flags); diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index 31a8068..1b5269e 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -9,6 +9,7 @@ #ifndef __LINUX_USB_PHY_H #define __LINUX_USB_PHY_H +#include #include #include @@ -85,6 +86,11 @@ struct usb_phy { struct usb_phy_io_ops *io_ops; void __iomem *io_priv; + /* to support extcon device */ + struct extcon_dev *edev; + struct notifier_block vbus_nb; + struct notifier_block id_nb; + /* for notification of usb_phy_events */ struct atomic_notifier_head notifier;