Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752471AbbDMELO (ORCPT ); Mon, 13 Apr 2015 00:11:14 -0400 Received: from mail-bn1bbn0109.outbound.protection.outlook.com ([157.56.111.109]:48739 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750742AbbDMELL (ORCPT ); Mon, 13 Apr 2015 00:11:11 -0400 X-Greylist: delayed 900 seconds by postgrey-1.27 at vger.kernel.org; Mon, 13 Apr 2015 00:11:10 EDT Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none; Date: Mon, 13 Apr 2015 11:53:46 +0800 From: Peter Chen To: "Ivan T. Ivanov" CC: Rob Herring , Pawel Moll , "Mark Rutland" , Ian Campbell , Kumar Gala , Greg Kroah-Hartman , , , , Subject: Re: [PATCH] usb: chipidea: Use extcon framework for VBUS and ID detection Message-ID: <20150413035345.GA1341@shlinux2> References: <1428568418-22508-1-git-send-email-ivan.ivanov@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <1428568418-22508-1-git-send-email-ivan.ivanov@linaro.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;BMV:1;SFV:NSPM;SFS:(10019020)(6009001)(339900001)(24454002)(199003)(51704005)(189002)(46406003)(46102003)(50466002)(19580395003)(19580405001)(83506001)(106466001)(33716001)(86362001)(575784001)(87936001)(6806004)(92566002)(105606002)(104016003)(77096005)(85426001)(50986999)(54356999)(76176999)(77156002)(62966003)(2950100001)(110136001)(33656002)(23726002)(4001350100001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM2PR0301MB1216;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;MLV:sfv;A:1;MX:1;LANG:en; X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1216; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5002010)(5005006);SRVR:DM2PR0301MB1216;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1216; X-Forefront-PRVS: 0545EFAC9A X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2015 03:56:07.3922 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB1216 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 8741 Lines: 288 On Thu, Apr 09, 2015 at 11:33:38AM +0300, Ivan T. Ivanov wrote: > 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(-) > > 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. You mean if id connector is not needed, we write dts like below: extcon = <&usb_vbus>, <0>; If it is, you may miss ',' between "required" and "empty <0>". > + > 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 Would you use "select" instead of "depends on" since some defconfigs may not enable 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 %s/exteternal/external > + * @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 %s/trakining/tracking > */ > 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; I prefer using vbus_extcon and id_extcon > }; > > 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) ci_id_notifier? > +{ > + 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); > + } Would you move this code to ci_get_platdata which is used to get platform stuffs from parent > + > + 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) { You may use "||" since you can't get vbus and id value from cpu register (otgsc). > + 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; > } > > /** > -- > 1.9.1 > -- Best Regards, Peter Chen -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/