From patchwork Wed Apr 15 13:35:15 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: 47188 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1E1512121F for ; Wed, 15 Apr 2015 13:35:35 +0000 (UTC) Received: by wgtl5 with SMTP id l5sf9832001wgt.1 for ; Wed, 15 Apr 2015 06:35:34 -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=PpeWnL054j+mBpqLhbGAYlgiFHon9Rk9Ul9X4sp8dBE=; b=WfZsCSpvgovNobGz+wZslMGd9ei8NLSRKdB+Jvbm6cGMP/130BmZFaLFvphH9o2Ev8 5Hm32UnGHxs7U8sgFVOaYDnLa4rTgIMHojH65Wmjaax/U20AIocckS7IP6KItefkppSO DsZw/EJxUx+pGTkcyGu5fPbWGIljCmebsI2fFhfa8DvF7wUSbtqypNN65+ZICjeKzX5Y /7CLOugTo7ziOrwzgfVOKmknxBw84ZfvROFaGx6hEHTacB7E0GBI2JP7GvdlK9cxz8f3 Ic7Z7aCko4sITsb4F2x73BJCDy7X94Xnz+xUW5RqqUaGRjUOjkFisJXsbGqnAmm3OO/u AXYA== X-Gm-Message-State: ALoCoQlMoRmS7LYeY5eDWqCUnSgk9keNVDa84+/1HTgSE+NFpqLWQISurk+761eviJ9MOE0V4Xgg X-Received: by 10.180.106.136 with SMTP id gu8mr4804975wib.6.1429104934430; Wed, 15 Apr 2015 06:35:34 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.178.195 with SMTP id da3ls200204lac.30.gmail; Wed, 15 Apr 2015 06:35:34 -0700 (PDT) X-Received: by 10.113.10.134 with SMTP id ea6mr23574041lbd.29.1429104934231; Wed, 15 Apr 2015 06:35:34 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id jf6si3904146lbc.170.2015.04.15.06.35.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Apr 2015 06:35:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by labbd9 with SMTP id bd9so32854578lab.2 for ; Wed, 15 Apr 2015 06:35:34 -0700 (PDT) X-Received: by 10.112.140.231 with SMTP id rj7mr23316821lbb.76.1429104934091; Wed, 15 Apr 2015 06:35:34 -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 l1csp2517586lbt; Wed, 15 Apr 2015 06:35:33 -0700 (PDT) X-Received: by 10.70.11.194 with SMTP id s2mr46460918pdb.143.1429104932116; Wed, 15 Apr 2015 06:35:32 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h4si7101141pat.146.2015.04.15.06.35.31; Wed, 15 Apr 2015 06:35:32 -0700 (PDT) Received-SPF: none (google.com: linux-usb-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 S1753572AbbDONf3 (ORCPT + 4 others); Wed, 15 Apr 2015 09:35:29 -0400 Received: from mail-wg0-f48.google.com ([74.125.82.48]:36738 "EHLO mail-wg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751813AbbDONf1 (ORCPT ); Wed, 15 Apr 2015 09:35:27 -0400 Received: by wgsk9 with SMTP id k9so47013368wgs.3 for ; Wed, 15 Apr 2015 06:35:26 -0700 (PDT) X-Received: by 10.194.5.74 with SMTP id q10mr49684948wjq.27.1429104926586; Wed, 15 Apr 2015 06:35:26 -0700 (PDT) Received: from localhost.localdomain ([37.157.136.206]) by mx.google.com with ESMTPSA id o6sm15645231wiz.24.2015.04.15.06.35.24 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Apr 2015 06:35:25 -0700 (PDT) From: "Ivan T. Ivanov" To: Peter Chen Cc: Kumar Gala , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , 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 v2] usb: chipidea: Use extcon framework for VBUS and ID detect Date: Wed, 15 Apr 2015 16:35:15 +0300 Message-Id: <1429104915-11079-1-git-send-email-ivan.ivanov@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-usb-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-usb@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.215.45 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 --- Changes since v0 [1], as per Peter Chen suggestions: * Moved external connector parsing code to ci_get_platdata() * Moved external connector related variables to struct ci_hdrc_platform_data * Rename ci_host_notifier() to ci_id_notifier() * Fixed device bindings description * Use select EXTCON framework, instead of depends on. [1] https://lkml.org/lkml/2015/4/9/116 .../devicetree/bindings/usb/ci-hdrc-qcom.txt | 9 +++ drivers/usb/chipidea/Kconfig | 1 + drivers/usb/chipidea/core.c | 87 ++++++++++++++++++++++ drivers/usb/chipidea/otg.c | 26 ++++++- include/linux/usb/chipidea.h | 17 +++++ 5 files changed, 139 insertions(+), 1 deletion(-) -- 1.9.1 -- 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/Documentation/devicetree/bindings/usb/ci-hdrc-qcom.txt b/Documentation/devicetree/bindings/usb/ci-hdrc-qcom.txt index f2899b5..c635aca 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 = <0>, <&usb_id>; }; diff --git a/drivers/usb/chipidea/Kconfig b/drivers/usb/chipidea/Kconfig index 5ce3f1d..5619b8c 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 + select 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/core.c b/drivers/usb/chipidea/core.c index 74fea4f..e1d495d 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -557,9 +558,39 @@ static irqreturn_t ci_irq(int irq, void *data) return ret; } +static int ci_vbus_notifier(struct notifier_block *nb, unsigned long event, + void *ptr) +{ + struct ci_hdrc_cable *vbus = container_of(nb, struct ci_hdrc_cable, nb); + + if (event) + vbus->state = true; + else + vbus->state = false; + + return NOTIFY_DONE; +} + +static int ci_id_notifier(struct notifier_block *nb, unsigned long event, + void *ptr) +{ + struct ci_hdrc_cable *id = container_of(nb, struct ci_hdrc_cable, nb); + + if (event) + id->state = false; + else + id->state = true; + + return NOTIFY_DONE; +} + static int ci_get_platdata(struct device *dev, struct ci_hdrc_platform_data *platdata) { + struct extcon_dev *ext_vbus, *ext_id; + struct ci_hdrc_cable *cable; + int ret; + if (!platdata->phy_mode) platdata->phy_mode = of_usb_get_phy_mode(dev->of_node); @@ -591,6 +622,53 @@ static int ci_get_platdata(struct device *dev, if (of_usb_get_maximum_speed(dev->of_node) == USB_SPEED_FULL) platdata->flags |= CI_HDRC_FORCE_FULLSPEED; + ext_id = ERR_PTR(-ENODEV); + ext_vbus = ERR_PTR(-ENODEV); + if (of_property_read_bool(dev->of_node, "extcon")) { + /* Each one of them is not mandatory */ + ext_vbus = extcon_get_edev_by_phandle(dev, 0); + if (IS_ERR(ext_vbus) && PTR_ERR(ext_vbus) != -ENODEV) + return PTR_ERR(ext_vbus); + + ext_id = extcon_get_edev_by_phandle(dev, 1); + if (IS_ERR(ext_id) && PTR_ERR(ext_id) != -ENODEV) + return PTR_ERR(ext_id); + } + + if (!IS_ERR(ext_vbus)) { + cable = &platdata->vbus_extcon; + cable->nb.notifier_call = ci_vbus_notifier; + ret = extcon_register_interest(&cable->conn, ext_vbus->name, + "USB", &cable->nb); + if (ret < 0) { + dev_err(dev, "register VBUS failed\n"); + return ret; + } + + ret = extcon_get_cable_state(ext_vbus, "USB"); + if (ret) + cable->state = true; + else + cable->state = false; + } + + if (!IS_ERR(ext_id)) { + cable = &platdata->id_extcon; + cable->nb.notifier_call = ci_id_notifier; + ret = extcon_register_interest(&cable->conn, ext_id->name, + "USB-HOST", &cable->nb); + if (ret < 0) { + dev_err(dev, "register ID failed\n"); + return ret; + } + + ret = extcon_get_cable_state(ext_id, "USB-HOST"); + if (ret) + cable->state = false; + else + cable->state = true; + } + return 0; } @@ -845,6 +923,7 @@ deinit_phy: static int ci_hdrc_remove(struct platform_device *pdev) { struct ci_hdrc *ci = platform_get_drvdata(pdev); + struct extcon_specific_cable_nb *cable_nb; if (ci->supports_runtime_pm) { pm_runtime_get_sync(&pdev->dev); @@ -852,6 +931,14 @@ static int ci_hdrc_remove(struct platform_device *pdev) pm_runtime_put_noidle(&pdev->dev); } + cable_nb = &ci->platdata->id_extcon.conn; + if (cable_nb->edev) + extcon_unregister_interest(cable_nb); + + cable_nb = &ci->platdata->vbus_extcon.conn; + if (cable_nb->edev) + extcon_unregister_interest(cable_nb); + 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 ad6c87a..34dd196 100644 --- a/drivers/usb/chipidea/otg.c +++ b/drivers/usb/chipidea/otg.c @@ -30,7 +30,31 @@ */ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask) { - return hw_read(ci, OP_OTGSC, mask); + struct ci_hdrc_cable *cable; + u32 val = hw_read(ci, OP_OTGSC, mask); + + /* + * If using extcon framework for VBUS and/or ID signal + * detection overwrite OTGSC resiter value + */ + cable = &ci->platdata->vbus_extcon; + if ((mask & OTGSC_BSV) && cable->conn.edev) { + if (cable->state) + val |= OTGSC_BSV; + else + val &= ~OTGSC_BSV; + } + + cable = &ci->platdata->id_extcon; + if ((mask & OTGSC_ID) && cable->conn.edev) { + if (cable->state) + val |= OTGSC_ID; + else + val &= ~OTGSC_ID; + } + + val &= mask; + return val; } /** diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h index ab94f78..0eedaf6 100644 --- a/include/linux/usb/chipidea.h +++ b/include/linux/usb/chipidea.h @@ -5,8 +5,21 @@ #ifndef __LINUX_USB_CHIPIDEA_H #define __LINUX_USB_CHIPIDEA_H +#include #include +/** + * struct ci_hdrc_cable - structure for external connector cable state tracking + * @state: current state of the line + * @nb: hold event notification callback + * @conn: used for notification registration + */ +struct ci_hdrc_cable { + bool state; + struct notifier_block nb; + struct extcon_specific_cable_nb conn; +}; + struct ci_hdrc; struct ci_hdrc_platform_data { const char *name; @@ -35,6 +48,10 @@ struct ci_hdrc_platform_data { void (*notify_event) (struct ci_hdrc *ci, unsigned event); struct regulator *reg_vbus; bool tpl_support; + + /* VBUS and ID signal state tracking, using extcon framework */ + struct ci_hdrc_cable vbus_extcon; + struct ci_hdrc_cable id_extcon; }; /* Default offset of capability registers */