From patchwork Fri Mar 17 06:19:20 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: 95408 Delivered-To: patch@linaro.org Received: by 10.140.89.134 with SMTP id v6csp164010qgd; Thu, 16 Mar 2017 23:19:49 -0700 (PDT) X-Received: by 10.98.15.7 with SMTP id x7mr15223722pfi.217.1489731589067; Thu, 16 Mar 2017 23:19:49 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b66si7585738pgc.50.2017.03.16.23.19.48; Thu, 16 Mar 2017 23:19:49 -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 S1750982AbdCQGTs (ORCPT + 4 others); Fri, 17 Mar 2017 02:19:48 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:35708 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750885AbdCQGTr (ORCPT ); Fri, 17 Mar 2017 02:19:47 -0400 Received: by mail-pf0-f170.google.com with SMTP id x63so29769824pfx.2 for ; Thu, 16 Mar 2017 23:19:46 -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=Dkvj7pVvQTVKf6XLv//wBJri2QLaxWo6oVF/y0pcBRc=; b=WnN25fzm/KpzcVP6qF6ixagIuk+rgrJZCxlaM2xQR0IPcDE20VfsHfNpDRHgO784fr djhihTGdEzPwXCRQNorRuDig84kIi7G5va8oT9gBzS7c9fQJKf//J9bR9I1F5Kgy6cXC UIfWBORrCovLVEjPYQD7ParOskAylq+p9CFsk= 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=Dkvj7pVvQTVKf6XLv//wBJri2QLaxWo6oVF/y0pcBRc=; b=HLsywRixQ0cCCESdqUCfj16S6oJmuk23PQsIT3K8fNMZkopy4qz6GgYpkHbsAXpFts PZaw43lAqvdSaCSoG/J6rqw4OfiBqV6KHNKKk9pGzUNClYftdq0Y5G857o+gmtjHtuzT Kyq6TSTqMUMbhBgs6bswYyMBgC+PI2M0dm0NftX62gIvXCn7YfP4SylQM5dbPvFo+LSs hH/3H/Ih78Oyaxqy5fclX9xHMMH5Wb0JRmZejhf1jq9FbAQfZu++QLgM6pZH5d8f5bQp Hssl9oZZ9IHmxz8VYe1meWa3qzCQjJV7ywwTGA8xM+T+7WFcrnwhP3c8wfN4IYGJaCNK EBuw== X-Gm-Message-State: AFeK/H06vb6sl2DAUcq+4M3Vug+spY7qxTZAr0CSE+mmcGwLk8ZsRY0ZCMt72p19gyzKbdPg X-Received: by 10.99.217.17 with SMTP id r17mr14279156pgg.140.1489731585708; Thu, 16 Mar 2017 23:19:45 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id f21sm14078100pfj.111.2017.03.16.23.19.41 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Mar 2017 23:19:45 -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 1/2] usb: phy: Introduce one extcon device into usb phy Date: Fri, 17 Mar 2017 14:19:20 +0800 Message-Id: <479fef31f632df7454225056054c081bb7ef9bf9.1489731114.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 --- drivers/usb/phy/Kconfig | 17 ++++++++++++++--- drivers/usb/phy/phy.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/phy.h | 6 ++++++ 3 files changed, 64 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..39fd6e7 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -13,6 +13,7 @@ config AB8500_USB tristate "AB8500 USB Transceiver Driver" depends on AB8500_CORE select USB_PHY + select EXTCON help Enable this to support the USB OTG transceiver in AB8500 chip. This transceiver supports high and full speed devices plus, @@ -23,6 +24,7 @@ config FSL_USB2_OTG depends on USB_EHCI_FSL && USB_FSL_USB2 && USB_OTG_FSM && PM depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' select USB_PHY + select EXTCON help Enable this to support Freescale USB OTG transceiver. @@ -32,6 +34,7 @@ config ISP1301_OMAP depends on USB depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' select USB_PHY + select EXTCON help If you say yes here you get support for the Philips ISP1301 USB-On-The-Go transceiver working with the OMAP OTG controller. @@ -55,6 +58,7 @@ config NOP_USB_XCEIV tristate "NOP USB Transceiver Driver" depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, NOP can't be built-in select USB_PHY + select EXTCON help This driver is to be used by all the usb transceiver which are either built-in with usb ip or which are autonomous and doesn't require any @@ -70,6 +74,7 @@ config AM335X_PHY_USB select USB_PHY select AM335X_CONTROL_USB select USB_COMMON + select EXTCON help This driver provides PHY support for that phy which part for the AM335x SoC. @@ -98,6 +103,7 @@ config USB_GPIO_VBUS depends on GPIOLIB || COMPILE_TEST depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' select USB_PHY + select EXTCON help Provides simple GPIO VBUS sensing for controllers with an internal transceiver via the usb_phy interface, and @@ -116,9 +122,10 @@ 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 + select EXTCON help Enable this to support USB transceiver on Tahvo. This is used at least on Nokia 770. @@ -135,6 +142,7 @@ config USB_ISP1301 depends on USB || USB_GADGET depends on I2C select USB_PHY + select EXTCON help Say Y here to add support for the NXP ISP1301 USB transceiver driver. This chip is typically used as USB transceiver for USB host, gadget @@ -148,8 +156,8 @@ 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 + select EXTCON help Enable this to support the USB OTG transceiver on Qualcomm chips. It handles PHY initialization, clock management, and workarounds @@ -162,9 +170,10 @@ 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 + select EXTCON help Enable this to support the USB transceiver on Qualcomm 8x16 chipsets. It handles PHY initialization, clock management, power management, @@ -178,6 +187,7 @@ config USB_MV_OTG depends on USB_EHCI_MV && USB_MV_UDC && PM && USB_OTG depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' select USB_PHY + select EXTCON help Say Y here if you want to build Marvell USB OTG transciever driver in kernel (including PXA and MMP series). This driver @@ -190,6 +200,7 @@ config USB_MXS_PHY depends on ARCH_MXC || ARCH_MXS select STMP_DEVICE select USB_PHY + select EXTCON help Enable this to support the Freescale MXS USB PHY. 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;