From patchwork Thu Apr 9 08:33:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ivan T. Ivanov" X-Patchwork-Id: 46914 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7341E218D6 for ; Thu, 9 Apr 2015 08:33:52 +0000 (UTC) Received: by lamp14 with SMTP id p14sf25307282lam.3 for ; Thu, 09 Apr 2015 01:33:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=mssYfA4KTvgUs6BQgfBiEmU8BEzdU5KQ94hl+BybAdE=; b=hcQS/xLxcHJzOYoaZaIU6EdDsmlLSTqVastfU1pLQEKOpWnUuxgV6H6eO59e6rh8ms wtbml8JTIRzhHvf+YDrrQICrq98JbphBI47FsEUyyIEqg5HyhYxzCYfa41bn6Hr2JOA+ rMrTBbMB5JFMilCqo4VTxPM59kOa0szJEh7bsDNBVrSW1H1AjuH/Gs6cLdf75q7Aw3El 8xHiWThjH/dn/dcHbNYVl5p+Izx+bhIdDQ99r8CjVwXjOnkalXclYUxvLbSyU981g3rk Q8WaW+oB3mZdmpqJlhuZx7a+apsMBi0Ei0m8S9sHzb2m5A97yx/fTUsFMpaofepQW33M AqSw== X-Gm-Message-State: ALoCoQnEyocn3ooSDulePexbRlLwFUah8PN4KJ32csnJIOu7osM+dgJNGrdlZxrP5zxF5K6i3NVj X-Received: by 10.152.116.115 with SMTP id jv19mr63077lab.9.1428568430928; Thu, 09 Apr 2015 01:33:50 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.38 with SMTP id p6ls241222lap.17.gmail; Thu, 09 Apr 2015 01:33:50 -0700 (PDT) X-Received: by 10.152.88.99 with SMTP id bf3mr3525000lab.97.1428568430749; Thu, 09 Apr 2015 01:33:50 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id zz9si3118319lbb.157.2015.04.09.01.33.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2015 01:33:50 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbbqq2 with SMTP id qq2so76918901lbb.3 for ; Thu, 09 Apr 2015 01:33:50 -0700 (PDT) X-Received: by 10.112.212.106 with SMTP id nj10mr26970234lbc.36.1428568430571; Thu, 09 Apr 2015 01:33:50 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp332827lbt; Thu, 9 Apr 2015 01:33:49 -0700 (PDT) X-Received: by 10.68.138.230 with SMTP id qt6mr54078814pbb.66.1428568428647; Thu, 09 Apr 2015 01:33:48 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i4si20461772pdd.147.2015.04.09.01.33.47; Thu, 09 Apr 2015 01:33:48 -0700 (PDT) Received-SPF: none (google.com: devicetree-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932290AbbDIIdp (ORCPT + 5 others); Thu, 9 Apr 2015 04:33:45 -0400 Received: from mail-wi0-f171.google.com ([209.85.212.171]:34175 "EHLO mail-wi0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754983AbbDIIdn (ORCPT ); Thu, 9 Apr 2015 04:33:43 -0400 Received: by widjs5 with SMTP id js5so49875998wid.1 for ; Thu, 09 Apr 2015 01:33:41 -0700 (PDT) X-Received: by 10.180.87.66 with SMTP id v2mr3979132wiz.51.1428568421880; Thu, 09 Apr 2015 01:33:41 -0700 (PDT) Received: from localhost.localdomain ([37.157.136.206]) by mx.google.com with ESMTPSA id fa8sm19102154wib.14.2015.04.09.01.33.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Apr 2015 01:33:41 -0700 (PDT) From: "Ivan T. Ivanov" To: Peter Chen Cc: Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Greg Kroah-Hartman , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH] usb: chipidea: Use extcon framework for VBUS and ID detection Date: Thu, 9 Apr 2015 11:33:38 +0300 Message-Id: <1428568418-22508-1-git-send-email-ivan.ivanov@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ivan.ivanov@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On recent Qualcomm platforms VBUS and ID lines are not routed to USB PHY LINK controller. Use extcon framework to receive connect and disconnect ID and VBUS notification. Signed-off-by: Ivan T. Ivanov --- Suggestions for better solution are welcome! .../devicetree/bindings/usb/ci-hdrc-qcom.txt | 9 +++ drivers/usb/chipidea/Kconfig | 1 + drivers/usb/chipidea/ci.h | 18 +++++ drivers/usb/chipidea/core.c | 77 ++++++++++++++++++++++ drivers/usb/chipidea/otg.c | 19 +++++- 5 files changed, 123 insertions(+), 1 deletion(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" 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/Documentation/devicetree/bindings/usb/ci-hdrc-qcom.txt b/Documentation/devicetree/bindings/usb/ci-hdrc-qcom.txt index f2899b5..788da49 100644 --- a/Documentation/devicetree/bindings/usb/ci-hdrc-qcom.txt +++ b/Documentation/devicetree/bindings/usb/ci-hdrc-qcom.txt @@ -7,6 +7,14 @@ Required properties: - usb-phy: phandle for the PHY device - dr_mode: Should be "peripheral" +Optional properties: +- extcon: phandles to external connector devices. First phandle + should point to external connector, which provide "USB" + cable events, the second should point to external connector + device, which provide "USB-HOST" cable events. If one of + the external connector devices is not required empty <0> + phandle should be specified. + Examples: gadget@f9a55000 { compatible = "qcom,ci-hdrc"; @@ -14,4 +22,5 @@ Examples: dr_mode = "peripheral"; interrupts = <0 134 0>; usb-phy = <&usbphy0>; + extcon = <&usb_vbus>, <&usb_id>; }; diff --git a/drivers/usb/chipidea/Kconfig b/drivers/usb/chipidea/Kconfig index 77b47d8..a67b67f 100644 --- a/drivers/usb/chipidea/Kconfig +++ b/drivers/usb/chipidea/Kconfig @@ -1,6 +1,7 @@ config USB_CHIPIDEA tristate "ChipIdea Highspeed Dual Role Controller" depends on ((USB_EHCI_HCD && USB_GADGET) || (USB_EHCI_HCD && !USB_GADGET) || (!USB_EHCI_HCD && USB_GADGET)) && HAS_DMA + depends on EXTCON help Say Y here if your system has a dual role high speed USB controller based on ChipIdea silicon IP. Currently, only the diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index 65913d4..04e7aee 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h @@ -13,6 +13,7 @@ #ifndef __DRIVERS_USB_CHIPIDEA_CI_H #define __DRIVERS_USB_CHIPIDEA_CI_H +#include #include #include #include @@ -132,6 +133,18 @@ struct hw_bank { }; /** + * struct ci_hdrc - structure for exteternal connector cable state tracking + * @state: current state of the line + * @nb: hold event notification callback + * @conn: used for notification registration + */ +struct ci_cable { + bool state; + struct notifier_block nb; + struct extcon_specific_cable_nb conn; +}; + +/** * struct ci_hdrc - chipidea device representation * @dev: pointer to parent device * @lock: access synchronization @@ -169,6 +182,8 @@ struct hw_bank { * @b_sess_valid_event: indicates there is a vbus event, and handled * at ci_otg_work * @imx28_write_fix: Freescale imx28 needs swp instruction for writing + * @vbus: VBUS signal state trakining, using extcon framework + * @id: ID signal state trakining, using extcon framework */ struct ci_hdrc { struct device *dev; @@ -211,6 +226,9 @@ struct ci_hdrc { bool id_event; bool b_sess_valid_event; bool imx28_write_fix; + + struct ci_cable vbus; + struct ci_cable id; }; static inline struct ci_role_driver *ci_role(struct ci_hdrc *ci) diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index a57dc88..0f805bd 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -646,9 +647,36 @@ static void ci_get_otg_capable(struct ci_hdrc *ci) dev_dbg(ci->dev, "It is OTG capable controller\n"); } +static int ci_vbus_notifier(struct notifier_block *nb, unsigned long event, + void *ptr) +{ + struct ci_cable *vbus = container_of(nb, struct ci_cable, nb); + + if (event) + vbus->state = true; + else + vbus->state = false; + + return NOTIFY_DONE; +} + +static int ci_host_notifier(struct notifier_block *nb, unsigned long event, + void *ptr) +{ + struct ci_cable *id = container_of(nb, struct ci_cable, nb); + + if (event) + id->state = false; + else + id->state = true; + + return NOTIFY_DONE; +} + static int ci_hdrc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; + struct extcon_dev *ext_vbus, *ext_id; struct ci_hdrc *ci; struct resource *res; void __iomem *base; @@ -702,6 +730,51 @@ static int ci_hdrc_probe(struct platform_device *pdev) ci->usb_phy = NULL; } + ext_id = ERR_PTR(-ENODEV); + ext_vbus = ERR_PTR(-ENODEV); + if (of_property_read_bool(dev->parent->of_node, "extcon")) { + /* Each one of them is not mandatory */ + ext_vbus = extcon_get_edev_by_phandle(dev->parent, 0); + if (IS_ERR(ext_vbus) && PTR_ERR(ext_vbus) != -ENODEV) + return PTR_ERR(ext_vbus); + + ext_id = extcon_get_edev_by_phandle(dev->parent, 1); + if (IS_ERR(ext_id) && PTR_ERR(ext_id) != -ENODEV) + return PTR_ERR(ext_id); + } + + if (!IS_ERR(ext_vbus)) { + ci->vbus.nb.notifier_call = ci_vbus_notifier; + ret = extcon_register_interest(&ci->vbus.conn, ext_vbus->name, + "USB", &ci->vbus.nb); + if (ret < 0) { + dev_err(&pdev->dev, "register VBUS failed\n"); + return ret; + } + + ret = extcon_get_cable_state(ext_vbus, "USB"); + if (ret) + ci->vbus.state = true; + else + ci->vbus.state = false; + } + + if (!IS_ERR(ext_id)) { + ci->id.nb.notifier_call = ci_host_notifier; + ret = extcon_register_interest(&ci->id.conn, ext_id->name, + "USB-HOST", &ci->id.nb); + if (ret < 0) { + dev_err(&pdev->dev, "register ID failed\n"); + return ret; + } + + ret = extcon_get_cable_state(ext_id, "USB-HOST"); + if (ret) + ci->id.state = false; + else + ci->id.state = true; + } + ret = ci_usb_phy_init(ci); if (ret) { dev_err(dev, "unable to init phy: %d\n", ret); @@ -807,6 +880,10 @@ static int ci_hdrc_remove(struct platform_device *pdev) { struct ci_hdrc *ci = platform_get_drvdata(pdev); + if (ci->id.conn.edev) + extcon_unregister_interest(&ci->id.conn); + if (ci->vbus.conn.edev) + extcon_unregister_interest(&ci->vbus.conn); dbg_remove_files(ci); ci_role_destroy(ci); ci_hdrc_enter_lpm(ci, true); diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c index a048b08..2e97c0d 100644 --- a/drivers/usb/chipidea/otg.c +++ b/drivers/usb/chipidea/otg.c @@ -30,7 +30,24 @@ */ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask) { - return hw_read(ci, OP_OTGSC, mask); + u32 val = hw_read(ci, OP_OTGSC, mask); + + if ((mask & OTGSC_BSV) && ci->vbus.conn.edev) { + if (ci->vbus.state) + val |= OTGSC_BSV; + else + val &= ~OTGSC_BSV; + } + + if ((mask & OTGSC_ID) && ci->id.conn.edev) { + if (ci->id.state) + val |= OTGSC_ID; + else + val &= ~OTGSC_ID; + } + + val &= mask; + return val; } /**