From patchwork Fri May 5 06:12:24 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: 98601 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp35816qge; Thu, 4 May 2017 23:13:41 -0700 (PDT) X-Received: by 10.99.115.71 with SMTP id d7mr1351048pgn.153.1493964821725; Thu, 04 May 2017 23:13:41 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1si4222420pld.200.2017.05.04.23.13.41; Thu, 04 May 2017 23:13:41 -0700 (PDT) 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; 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 S1755764AbdEEGN1 (ORCPT + 25 others); Fri, 5 May 2017 02:13:27 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:35913 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755674AbdEEGNY (ORCPT ); Fri, 5 May 2017 02:13:24 -0400 Received: by mail-pf0-f179.google.com with SMTP id q66so18046932pfi.3 for ; Thu, 04 May 2017 23:13:23 -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:in-reply-to:references :in-reply-to:references; bh=8RCzzRIKAFEBG5SiBs1/kmVrGDmE1UgcDoor4CJSaQw=; b=JYgXbImlbRvuBh/PGMJDiNNf44BFDnLt7wI+79sE0oNWuEXi+s4SJnE5C8IG72siee ZT90wTglkqLvYaVWKaTox9LseODlcMWbUgUlAUoCG2KvLmx72R/khTRwuQA8/mJtN145 xVI1/ZHIbbMdJ+4U9MispDKFOZ36xcKfa1cKY= 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:in-reply-to :references:in-reply-to:references; bh=8RCzzRIKAFEBG5SiBs1/kmVrGDmE1UgcDoor4CJSaQw=; b=EEPlkac9dJKqmR5OtL8ZQHOypTwF90Otf7mR9YQWEV68fXvnywGyOaGX98Y1OZlZ80 yo9E9Q7yU20dkkUm+l2zXbmp+Y9vTcFJ91/4/Pxhw4GddsunR/7LLbtwqPg0hkoyIf03 8Jt5cCMkUQ0OSqtKENS+ZV3uvUGy6GsUgdz1/h3cLi2tIqrRt6/WtWnuOgPA9LgYJCzQ VuNYvx769AdZD+gfYSKUfNTXJU0jTBj0nwJA2TtmbifkYdu3MirOxBVAnFGDlswPfqIh LebLAyTuCvMP50n2CKRA/QuqXJ91l9XvE/BltSMaPOLanW07XsR7ep6i0I5N5rkjm1XL axtw== X-Gm-Message-State: AN3rC/5E3uLyiFEpuKocIf5dv9MtW0xWZTUor0xUgbh1bJX729XdqXxC +9VYSnEPuTLhG7Q0 X-Received: by 10.98.97.195 with SMTP id v186mr15040599pfb.81.1493964803297; Thu, 04 May 2017 23:13:23 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id l198sm1298760pga.50.2017.05.04.23.13.20 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 May 2017 23:13:22 -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 v3 1/3] usb: phy: Introduce one extcon device into usb phy Date: Fri, 5 May 2017 14:12:24 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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. Signed-off-by: Baolin Wang --- drivers/usb/phy/Kconfig | 6 ++--- drivers/usb/phy/phy.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/phy.h | 7 ++++++ 3 files changed, 67 insertions(+), 3 deletions(-) -- 1.7.9.5 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..032f5af 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c @@ -100,6 +100,54 @@ 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); + + x->id_edev = extcon_get_edev_by_phandle(x->dev, 1); + if (IS_ERR(x->id_edev)) { + x->id_edev = NULL; + dev_info(x->dev, "No separate ID extcon device\n"); + } + + 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) { + struct extcon_dev *id_ext; + + if (x->id_edev) + id_ext = x->id_edev; + else + id_ext = x->edev; + + ret = devm_extcon_register_notifier(x->dev, id_ext, + 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 +436,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 +474,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..2992451 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,12 @@ struct usb_phy { struct usb_phy_io_ops *io_ops; void __iomem *io_priv; + /* to support extcon device */ + struct extcon_dev *edev; + struct extcon_dev *id_edev; + struct notifier_block vbus_nb; + struct notifier_block id_nb; + /* for notification of usb_phy_events */ struct atomic_notifier_head notifier; From patchwork Fri May 5 06:12:26 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: 98602 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp35819qge; Thu, 4 May 2017 23:13:42 -0700 (PDT) X-Received: by 10.98.152.65 with SMTP id q62mr5910724pfd.256.1493964822091; Thu, 04 May 2017 23:13:42 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1si4222420pld.200.2017.05.04.23.13.41; Thu, 04 May 2017 23:13:42 -0700 (PDT) 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; 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 S932070AbdEEGNc (ORCPT + 25 others); Fri, 5 May 2017 02:13:32 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:34806 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755781AbdEEGN3 (ORCPT ); Fri, 5 May 2017 02:13:29 -0400 Received: by mail-pg0-f42.google.com with SMTP id 12so3752414pgc.1 for ; Thu, 04 May 2017 23:13:29 -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:in-reply-to:references :in-reply-to:references; bh=jwPXkZ0pt/I1Wv28bZqk3cgOvHXBKN8ZIx6+QOBvv2c=; b=h18s7QB5EFEx8hTzDhvOU/7qcsdPVJU5ure27tjLK37+ZxDUvePOu7dHcb14qsKVVC 4/+lKuJgQKnRXpvDH67ArYp5KywEQBf7zIEyc4+lkLwftWLAPbywVYub1Keo2N6mfkuc ZvvKO/oVoDZKmbTSAsdZlR+QuhvJPCYf9yqhg= 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:in-reply-to :references:in-reply-to:references; bh=jwPXkZ0pt/I1Wv28bZqk3cgOvHXBKN8ZIx6+QOBvv2c=; b=gmZZTGray6DaiDW+2776ItsL4FR5BXRkuZSTN5+R1/HVzs/38ssIuXleAyTUD94Vib xaX9OrG7h1ji57xMhrZFXPJNmS4cwjn+I+ieRN07nALu9n2fnUWUaiGDkcHa2bUONZuh vM6+tX4rULKDGqYs4f2kFkK2SdHj3tnLTHs9D/PstbMznt7V9NtEe8vm1Cdn1+eSpmAt /99/K+JxckccQpZ5LQmFrdxIkXPWTFRuGuRpZ1hefKHZMHXlZGzV73sfHis62i1Zt1GY cEyuphlgfrfRRnR45/Opbw1SpbNvsTb0t0Y/g9ABptWIAdBaHnRMgpeS6MGV+4VApy31 YzgA== X-Gm-Message-State: AN3rC/7yjy4EHqIvOeVCuQ4aAqYTx3UZI+AbTxPpXfk5DC6ICNhs2Y4b X4jzFTm0Jkvk3LTw X-Received: by 10.99.94.66 with SMTP id s63mr1367927pgb.34.1493964809054; Thu, 04 May 2017 23:13:29 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id l198sm1298760pga.50.2017.05.04.23.13.26 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 May 2017 23:13:28 -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 v3 3/3] usb: phy: phy-msm-usb: Remove redundant extcon register/unregister Date: Fri, 5 May 2017 14:12:26 +0800 Message-Id: <4e011c4c3720739a87ac309eb66e9de5c00b34f3.1493963244.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since usb phy core has added common code to register or unregister extcon device, then phy-msm-usb driver does not need its own code to register/unregister extcon device, then remove them. Signed-off-by: Baolin Wang --- drivers/usb/phy/phy-msm-usb.c | 85 +++++++++-------------------------------- 1 file changed, 18 insertions(+), 67 deletions(-) -- 1.7.9.5 diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c index 93d9aaa..8fb86a5 100644 --- a/drivers/usb/phy/phy-msm-usb.c +++ b/drivers/usb/phy/phy-msm-usb.c @@ -146,17 +146,6 @@ struct msm_otg_platform_data { }; /** - * struct msm_usb_cable - structure for exteternal connector cable - * state tracking - * @nb: hold event notification callback - * @conn: used for notification registration - */ -struct msm_usb_cable { - struct notifier_block nb; - struct extcon_dev *extcon; -}; - -/** * struct msm_otg: OTG driver data. Shared by HCD and DCD. * @otg: USB OTG Transceiver structure. * @pdata: otg device platform data. @@ -215,9 +204,6 @@ struct msm_otg { bool manual_pullup; - struct msm_usb_cable vbus; - struct msm_usb_cable id; - struct gpio_desc *switch_gpio; struct notifier_block reboot; }; @@ -1612,8 +1598,8 @@ static void msm_otg_debugfs_cleanup(void) static int msm_otg_vbus_notifier(struct notifier_block *nb, unsigned long event, void *ptr) { - struct msm_usb_cable *vbus = container_of(nb, struct msm_usb_cable, nb); - struct msm_otg *motg = container_of(vbus, struct msm_otg, vbus); + struct usb_phy *usb_phy = container_of(nb, struct usb_phy, vbus_nb); + struct msm_otg *motg = container_of(usb_phy, struct msm_otg, phy); if (event) set_bit(B_SESS_VLD, &motg->inputs); @@ -1636,8 +1622,8 @@ static int msm_otg_vbus_notifier(struct notifier_block *nb, unsigned long event, static int msm_otg_id_notifier(struct notifier_block *nb, unsigned long event, void *ptr) { - struct msm_usb_cable *id = container_of(nb, struct msm_usb_cable, nb); - struct msm_otg *motg = container_of(id, struct msm_otg, id); + struct usb_phy *usb_phy = container_of(nb, struct usb_phy, id_nb); + struct msm_otg *motg = container_of(usb_phy, struct msm_otg, phy); if (event) clear_bit(ID, &motg->inputs); @@ -1652,7 +1638,6 @@ static int msm_otg_id_notifier(struct notifier_block *nb, unsigned long event, static int msm_otg_read_dt(struct platform_device *pdev, struct msm_otg *motg) { struct msm_otg_platform_data *pdata; - struct extcon_dev *ext_id, *ext_vbus; struct device_node *node = pdev->dev.of_node; struct property *prop; int len, ret, words; @@ -1708,54 +1693,6 @@ static int msm_otg_read_dt(struct platform_device *pdev, struct msm_otg *motg) if (IS_ERR(motg->switch_gpio)) return PTR_ERR(motg->switch_gpio); - ext_id = ERR_PTR(-ENODEV); - ext_vbus = ERR_PTR(-ENODEV); - if (of_property_read_bool(node, "extcon")) { - - /* Each one of them is not mandatory */ - ext_vbus = extcon_get_edev_by_phandle(&pdev->dev, 0); - if (IS_ERR(ext_vbus) && PTR_ERR(ext_vbus) != -ENODEV) - return PTR_ERR(ext_vbus); - - ext_id = extcon_get_edev_by_phandle(&pdev->dev, 1); - if (IS_ERR(ext_id) && PTR_ERR(ext_id) != -ENODEV) - return PTR_ERR(ext_id); - } - - if (!IS_ERR(ext_vbus)) { - motg->vbus.extcon = ext_vbus; - motg->vbus.nb.notifier_call = msm_otg_vbus_notifier; - ret = devm_extcon_register_notifier(&pdev->dev, ext_vbus, - EXTCON_USB, &motg->vbus.nb); - if (ret < 0) { - dev_err(&pdev->dev, "register VBUS notifier failed\n"); - return ret; - } - - ret = extcon_get_state(ext_vbus, EXTCON_USB); - if (ret) - set_bit(B_SESS_VLD, &motg->inputs); - else - clear_bit(B_SESS_VLD, &motg->inputs); - } - - if (!IS_ERR(ext_id)) { - motg->id.extcon = ext_id; - motg->id.nb.notifier_call = msm_otg_id_notifier; - ret = devm_extcon_register_notifier(&pdev->dev, ext_id, - EXTCON_USB_HOST, &motg->id.nb); - if (ret < 0) { - dev_err(&pdev->dev, "register ID notifier failed\n"); - return ret; - } - - ret = extcon_get_state(ext_id, EXTCON_USB_HOST); - if (ret) - clear_bit(ID, &motg->inputs); - else - set_bit(ID, &motg->inputs); - } - prop = of_find_property(node, "qcom,phy-init-sequence", &len); if (!prop || !len) return 0; @@ -1932,6 +1869,8 @@ static int msm_otg_probe(struct platform_device *pdev) phy->init = msm_phy_init; phy->notify_disconnect = msm_phy_notify_disconnect; phy->type = USB_PHY_TYPE_USB2; + phy->vbus_nb.notifier_call = msm_otg_vbus_notifier; + phy->id_nb.notifier_call = msm_otg_id_notifier; phy->io_ops = &msm_otg_io_ops; @@ -1947,6 +1886,18 @@ static int msm_otg_probe(struct platform_device *pdev) goto disable_ldo; } + ret = extcon_get_state(phy->edev, EXTCON_USB); + if (ret) + set_bit(B_SESS_VLD, &motg->inputs); + else + clear_bit(B_SESS_VLD, &motg->inputs); + + ret = extcon_get_state(phy->id_edev, EXTCON_USB_HOST); + if (ret) + clear_bit(ID, &motg->inputs); + else + set_bit(ID, &motg->inputs); + platform_set_drvdata(pdev, motg); device_init_wakeup(&pdev->dev, 1);