Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752249AbbEZJPl (ORCPT ); Tue, 26 May 2015 05:15:41 -0400 Received: from [157.56.111.103] ([157.56.111.103]:27773 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752025AbbEZJPi (ORCPT ); Tue, 26 May 2015 05:15:38 -0400 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none; Date: Tue, 26 May 2015 17:13:37 +0800 From: Peter Chen To: "Ivan T. Ivanov" CC: Kumar Gala , Rob Herring , "Pawel Moll" , Mark Rutland , Ian Campbell , Greg Kroah-Hartman , , , , Subject: Re: [PATCH v2] usb: chipidea: Use extcon framework for VBUS and ID detect Message-ID: <20150526091335.GA1270@shlinux2> References: <1429104915-11079-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: <1429104915-11079-1-git-send-email-ivan.ivanov@linaro.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11FD052;1:CWZTGTDTotM3G2AD0+Vu0/dnkKv8J+IncynsIQHcxLdd5b71ZfO1LSTqmf+DFoEYTfRbpLHjTYsZh79PqzzqqHsbdzgbwsKP1vKZrueRENq/EYDWci++bu/pqcNqGMNUxeif4/1vx1VfDxWWEXZbpmGqiOXwswggXCbHIGJ1SVyqADCCTfqFiGeTujPFKiFCs5cIQsVB92sSmdGZYHLNmZDVjVznG5/ZZqLAbrUXf1HRarWMP/S3hqhmw3FhSZ0uFQrZYoOv9Nko8UXxaDZK83GVjySR2zszB7w7qzn52WQV8KhdGzmSANwq1LyKDTY4 X-Forefront-Antispam-Report: CIP:192.88.158.2;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(339900001)(24454002)(199003)(51704005)(189002)(62966003)(4001540100001)(77156002)(81156007)(4001350100001)(5001860100001)(97736004)(46102003)(86362001)(23726002)(50466002)(15975445007)(77096005)(105606002)(68736005)(92566002)(33716001)(2950100001)(5001960100002)(110136002)(189998001)(87936001)(47776003)(5001830100001)(33656002)(85426001)(46406003)(50986999)(76176999)(54356999)(6806004)(106466001)(64706001)(104016003)(97756001)(19580395003)(69596002)(19580405001)(83506001);DIR:OUT;SFP:1102;SCL:1;SRVR:CY1PR0301MB1274;H:az84smr01.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB1274;2:8Oz0WEzatHnrUu00ugxvpAZ1JNU5tQdA0pTlbQf4TBZav4jJhQ0Q5nuFJ4TDDRIP;2:Pysz17LItW1mFNEIi4BqKUDTSCMVQc1yHD3d27YW8XdoHPsVbXUNjESIVHPApQ+TSRcwdFFTbbKTNLLfHMCfSs7CbQ99T+K1yF/84VrpTlbgDRDDSpRFIDq/vGkxHRcy4jFlEzCFT3kCXcA//qN4v52Lo6wZjdzomUGO+lJib/YLbGO1CbffSP8ziFxCs/AjP0CMS9stdMQ/l6LitlTLlewTvYMbK0p8Ax1MHG99qOM=;6:jjvv7Ju8+axoxLmq5VUNRvvJcePPDUb2jW2c2mJE9rh1EQGeZ1s9jqB+PlokQ5p8qW6zaJTgHik/QQHzlDOphxAAdGkD9U9alNwRzFWREBYphtMnDU60kWjwvfYiP7YtPUbwybgoC8p7aOGf0A7hfu+BjAv5pHfuqPZiCd02y9tWAIZtOI8BU55pSKlMChBcF2yi75L4JbgS8tqdnEMwQtfG0wBgVbfL1q6SFELZBKtAhZpzxA67B2KQDc8hgZ9dI5UoZbAx06FyrALhS5iKv1m+yPZDEtg/iqkb6JVD3B17Eex2ir3/G94kQ1hoOepkPDUC1LYRwN7+RkYcr1kp2w== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB1274; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(520002)(3002001);SRVR:CY1PR0301MB1274;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB1274; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB1274;3:oZfy6IHD4OA6tjKk0K+xXDhW32chPOaBX4Aa7sKVQXT1SKw1kFqGfwLw/h0c5yC3N7ZLRkXE5XJUjiFHbgR7moJUEQpUDMXm6X6Xo332sDfMbeb2mxNXuQNj7+tpal7TWsk5P0Ypb/quHB3uuFJsfjpGcj6wvPlYP5mAoZ2CVEmOVTUGiPkqj0HZb1ZaCNXaa9r4m1E+EHSUSrMxGfqXMf82U6Kmi/0AEAd49HU10wwVZkqkKhKaP5ID6GtQZvkSeb8mzM+4S6D1wMP9mg1KwYTIGsaqQJAKQNefCYVETvVhmw6XnF3VERo4XIRX++P0 X-Forefront-PRVS: 0588B2BD96 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR0301MB1274;9:TH+tx/xi7BzSaM3bU3exCPy1xFN6F44tVzNzW/8N?= =?us-ascii?Q?r1Dy5Q/z30CfviEbOb3odbuKiHTllWNdic+NfxQvt5U6LfQUUfe5FgmDDp5O?= =?us-ascii?Q?31zWqK7qz8pi7f5yIJGZCCUUlwUs0N0mbTfFaEO4qaGyExPia3TuDpCX8rgZ?= =?us-ascii?Q?u19WioY5j5CrotEbbZFJcxjbpOVSFZaLl5kUt16MtY9ne7pVQ3HR0qVWNSJ1?= =?us-ascii?Q?qrRJL3vB5n46fzWQZKmJZv2TsiyY1bHIx/qt2i/rp1y4ew+jzMyl/imtM08g?= =?us-ascii?Q?eLC4e+IDZhK2ZHyt9/EEHlnt0vGo9e3sERJNdSqRl8xnLTnmqrekfnERrO4e?= =?us-ascii?Q?XcEGp7WISUgoWB3wnERUMKfhU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OwAqLIPyDXdmOXHtGrjhK8h66Ce4NGoLTjB8GR1+J/M/YJSvceTkVxQkI/WHYbbRyv32OAFFu8WREGqGsgMtiTZbzRpcmQo8coYE9PPe/EY+s91YLuuydi6emftpkkgkvbK3QXZv8Fctog==;10:jh+lQaF6pMcV9eA2e6TrRuFttvx8udDkiQHOgnKAP5tD36Go+NMKXsNP219pv/7AksMwKbZFwBgH3G1n5pXBFVe9G9ClFyc/9zNNbveZvF8=;6:Yoc2De3AXLLtGdXSvH1seczAG9bV+rloyvwyuEwA83No7Md/sdkueIUBW/Wmz2EB X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2015 09:14:34.3864 (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.158.2];Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0301MB1274 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9015 Lines: 285 On Wed, Apr 15, 2015 at 04:35:15PM +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 > --- > > 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(-) > > 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 */ > -- > 1.9.1 > I have not found the handler for id/vbus change, eg, when the vbus has changed, the ci_handle_vbus_change should be called? Chanwoo Choi has some updates for id/vbus, make sure you work well for his new patch set[1]. [1]: https://lkml.org/lkml/2015/5/22/346 -- 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/