From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754562AbbIHKvY (ORCPT ); Tue, 8 Sep 2015 06:51:24 -0400 Received: from mail-by2on0116.outbound.protection.outlook.com ([207.46.100.116]:65190 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754029AbbIHKvU (ORCPT ); Tue, 8 Sep 2015 06:51:20 -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;vger.kernel.org; dmarc=none action=none header.from=freescale.com; Date: Tue, 8 Sep 2015 17:39:07 +0800 From: Peter Chen To: "Ivan T. Ivanov" CC: Rob Herring , Pawel Moll , "Mark Rutland" , Ian Campbell , Kumar Gala , Greg Kroah-Hartman , Antoine Tenart , , , , Subject: Re: [PATCH v4] usb: chipidea: Use extcon framework for VBUS and ID detect Message-ID: <20150908093906.GE7802@shlinux2> References: <1441626325-20983-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: <1441626325-20983-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;BY2FFO11FD008;1:BhDJiWNA5f8CpiJtpQsumtB/zqhaHvvSmoQjMN50qqnfqlVfEL65bdReRvIIbrllZbGQBbC0CsqBNcu04BRhXR9xQJZnj1PUMqVSksvroxk6H4lem/CqTaoXcFjs/R3T0PRxYtxZkjYA/PUa0erCB1gVdEC2tADWYRL7yAG9rH4PJGgJZ1glt3+DdP4Gu1PgOSxrDMh85hXQVad05HPch5rL5I+SVFBoYjOdC3TzupP4GdxLk7ZmAv034cy/4zcU+JpJseX+K9aticMGcAkTLlmnzjca/xYGSilppgKteznAq0izvJtw2eINqHATxWq7vCrRgT2tLbF8iNPk97+yf7iFXmXe892cwd5qXFtVacNkjx64Tl8qxpYQrU9Got4A X-Forefront-Antispam-Report: CIP:192.88.158.2;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(1109001)(339900001)(199003)(189002)(24454002)(86362001)(2950100001)(50466002)(54356999)(83506001)(68736005)(77156002)(106466001)(33656002)(33716001)(19580405001)(69596002)(6806004)(47776003)(77096005)(62966003)(92566002)(23726002)(15975445007)(87936001)(19580395003)(50986999)(4001350100001)(76176999)(5001830100001)(46102003)(81156007)(575784001)(105606002)(5007970100001)(85426001)(189998001)(5001860100001)(46406003)(110136002)(97756001)(104016003)(5001960100002)(97736004)(4001540100001)(64706001);DIR:OUT;SFP:1102;SCL:1;SRVR:BY2PR03MB489;H:az84smr01.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB489;2:K3uIoV9UaWhj3E2WY6mh1m5XXtIESZRk5zMfzVi8UJr6VW7OfOR2IeOcfFItTk8HUJObJ3WXWzIMYYntwTjtiS5Nz2tnFzWbnx0BzbwRNG3Sfw41QtW+r+1gnwtu6Ch253q7lRgjOcpTxGatNSaGG3e8EpkMJJATt0hz6sc4XRI=;3:fVkWhdl7S/cIHIqv7xkxf9p5NvOnf/3sRYAo9BsDOEV5ORFSYJiTqyrqOBFUA1XS43wd4h8Xv9tGK4Yv1RsLrYzaU0hXudxEp4qbzLlDsvztpV+2sq33/tN+Fidi3GNJQyyr/kNuJ7DivO4w1rzdCHFvg9+5Rls0Dpugox+Iq0t0wQHceJNnEyUaRPKg/YUaix4rfE3SQLW2yFA/2akflGcgrQ0yZNQgbuofssNeeq4=;25:E3rsh5Gx522KmflTdxm4BHMmPlWh7aB19PDaF3ElFLruwNJbFVhjCs5DgLlhRfq9t2W6Mi5d8C8jHxH6IxjVS5rnZ5qvkqpqmwiLunm772QooAIkkq2MYUQqy6dHPlapZBUNb+Odt9g3BufeCZW8uEZMcQEdCIDcdOpcFvQk/8UXdFiltt46LEXJcfMALEcWkwTHnYqDDD4lrpp5qIcedlgVr5gcoX7UTyS5ASOmazQGQfavsrZ4RrfkliilK6HBaGP67BZYaBd+YXNgAWZfWg== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB489; X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB489;20:/eiwTCEA2JSz3hHsREnWnpl+NSqow2dJnjpRPgY3BJXa/nwT5egfP4wFpgiOD7t8nWJlM/uVWkwNZy8XaFztKgJ3nOANfXYhdzkAsYT2eVyucESKsU6p/FGixNJSDa+Vzwrcdqa/FBOF9R9EoZ4ADNDjE3Oi3RRP4AlFR9D/nZJ+Owr6wKzwkTH4FLPMUa9mkC6FXrQCMtyF8f9V+FobILgLe9Ze1pvi4eJFrxsbFdGA1YaOqK9GmhJ2px2FUrUWxQ7jCO3LCQlGWUOmlenbA5hCaED2avB3YaER4z8aYM6wmWjeB07g6RxgiFJORq7dviTTC2c+vz/3FLsRvVFJ0jgBd5kvlhvjhmfMnQTpWnk=;4:KSuRgrofdSb+bMyoQx9805ayNEd7qx6czR0nEvbY5IteTpc+oGMVHC8IJW9SR+t+dGRWrdR2tB8NGjRuSp45omCzrY0nIDDzUEZyNTcGcsisuVlPzmbc868E706raa5pmkij4/VcYnbbLvqUEho04bsWgG3akHVLeR/d/xxbAD920n1oDe9lgbyUpW7Xeqer6qtbzfLFzHPs2iy1hQ66xyIr3CHtsxU99aKstVppGtpGjNeeoWeKK0GfIjfEZeKvnn+WubYDVFMQyUpGKx83/3dK0lK0TTIWB2Kj9N/IfKHcc09kE3gvrrYQukSp9jAhKUhKv/CeTkqROPQwHzY/qA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(8121501046)(5005006)(3002001);SRVR:BY2PR03MB489;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB489; X-Forefront-PRVS: 069373DFB6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY2PR03MB489;23:r1n+6J6f5p2wkL4xJrIT7YMqw+Jd87GRq5m8Oq9GRz?= =?us-ascii?Q?x+IvHq7ADdKjq0JUN+5KtVYMZEvmNX3JTzGScYhvDvh5yZQ3XoZwSo1sXlBj?= =?us-ascii?Q?8xr17037dmNybQRN6R65ninOrpE3anzDm7RUC0zt39djiklJCXe6ImZ/NbqR?= =?us-ascii?Q?YQx2Jw9oMWdpmDCR4hbrIuktz53prYwJFzeTsjds3tIEJcudmjGhinUyTmxy?= =?us-ascii?Q?d14/X4rnackrWKB079iyeC7H8Kf5iM1S+usbIB184r/XdloYlzbRPgJ07Ssp?= =?us-ascii?Q?mSasQ8nGIT+xwIFCwcMcHFXRpXNWeTuRkWDTbwZvBKprxKaMn7fSzyuIYfz7?= =?us-ascii?Q?V1fzRMpKV6rddyntXSe/yztFsGCu015aBMawn4wWbTg37N6t12vbLFnfQIhg?= =?us-ascii?Q?cbDrgSpxsjCs1o6cjVMr01UsnyN6rxYfroHFwip4e4hQs3y6x/CA3Iak1vEr?= =?us-ascii?Q?fswQ34Ku+1uVtfn+glP3zNjzcRNfkqHsvfB7acIN8/iQCIfL/sl2zT+e6tuF?= =?us-ascii?Q?ckEOGygUmWMQxsDiVs/O4P2Lm0R2Bha6jw1L9GPD/Y8sApgL5Sn4AYYPQ6UC?= =?us-ascii?Q?EXF94642WxH7BPYKidIicjDcR7SPVNyX5Nl9l8fyrb6KlvjGfTplsN25R0le?= =?us-ascii?Q?Ki7CnkDxDVVTGxHcq6HheI8PBhJH57ckAix1bwxk/x4ZBwf0dSgKtVi7ZMgA?= =?us-ascii?Q?7X1T8NjV1Tbe3UOrIytW8C0aKfsx1V+1nx93+cjGQ9FNSkNpGBS5gI0PJZmT?= =?us-ascii?Q?3k1dD288Vb9lze8MJ00VipbMaJLEVcU3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SPM X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Sep 2015 10:51:17.9932 (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: BY2PR03MB489 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 07, 2015 at 02:45:25PM +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 I will queue it for next rc1, thanks. Peter > --- > > Changes sice v3 [1]: > > * Migrate to new extcon framework API > * Address comments from Peter Chen. > > Tested DRD role with "qcom,ci-hdrc" and "qcom,usb-8x16-phy" on DB410c > > [1] https://lkml.org/lkml/2015/6/2/333 > > .../devicetree/bindings/usb/ci-hdrc-usb2.txt | 6 + > drivers/usb/chipidea/Kconfig | 1 + > drivers/usb/chipidea/core.c | 125 +++++++++++++++++++++ > drivers/usb/chipidea/otg.c | 39 ++++++- > include/linux/usb/chipidea.h | 23 ++++ > 5 files changed, 193 insertions(+), 1 deletion(-) > > diff --git a/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt b/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt > index d71ef07bca5d..aea7d0af5fd6 100644 > --- a/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt > +++ b/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt > @@ -45,6 +45,11 @@ Optional properties: > (4 bytes), This register represents the maximum length of a the burst > in 32-bit words while moving data from the USB bus to system memory, > changing this value takes effect only the SBUSCFG.AHBBRST is 0. > +- 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. > > Example: > > @@ -61,4 +66,5 @@ Example: > ahb-burst-config = <0x0>; > tx-burst-size-dword = <0x10>; /* 64 bytes */ > rx-burst-size-dword = <0x10>; > + extcon = <0>, <&usb_id>; > }; > diff --git a/drivers/usb/chipidea/Kconfig b/drivers/usb/chipidea/Kconfig > index 5ce3f1d6a6ed..5619b8ca3bf3 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 3feebf7f31f0..573c2876b263 100644 > --- a/drivers/usb/chipidea/core.c > +++ b/drivers/usb/chipidea/core.c > @@ -47,6 +47,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -602,9 +603,45 @@ 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); > + struct ci_hdrc *ci = vbus->ci; > + > + if (event) > + vbus->state = true; > + else > + vbus->state = false; > + > + vbus->changed = true; > + > + ci_irq(ci->irq, ci); > + 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); > + struct ci_hdrc *ci = id->ci; > + > + if (event) > + id->state = false; > + else > + id->state = true; > + > + id->changed = true; > + > + ci_irq(ci->irq, ci); > + 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) > @@ -695,9 +732,91 @@ static int ci_get_platdata(struct device *dev, > platdata->flags |= CI_HDRC_OVERRIDE_RX_BURST; > } > > + 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); > + } > + > + cable = &platdata->vbus_extcon; > + cable->nb.notifier_call = ci_vbus_notifier; > + cable->edev = ext_vbus; > + > + if (!IS_ERR(ext_vbus)) { > + ret = extcon_get_cable_state_(cable->edev, EXTCON_USB); > + if (ret) > + cable->state = true; > + else > + cable->state = false; > + } > + > + cable = &platdata->id_extcon; > + cable->nb.notifier_call = ci_id_notifier; > + cable->edev = ext_id; > + > + if (!IS_ERR(ext_id)) { > + ret = extcon_get_cable_state_(cable->edev, EXTCON_USB_HOST); > + if (ret) > + cable->state = false; > + else > + cable->state = true; > + } > return 0; > } > > +static int ci_extcon_register(struct ci_hdrc *ci) > +{ > + struct ci_hdrc_cable *id, *vbus; > + int ret; > + > + id = &ci->platdata->id_extcon; > + id->ci = ci; > + if (!IS_ERR(id->edev)) { > + ret = extcon_register_notifier(id->edev, EXTCON_USB_HOST, > + &id->nb); > + if (ret < 0) { > + dev_err(ci->dev, "register ID failed\n"); > + return ret; > + } > + } > + > + vbus = &ci->platdata->vbus_extcon; > + vbus->ci = ci; > + if (!IS_ERR(vbus->edev)) { > + ret = extcon_register_notifier(vbus->edev, EXTCON_USB, > + &vbus->nb); > + if (ret < 0) { > + extcon_unregister_notifier(id->edev, EXTCON_USB_HOST, > + &id->nb); > + dev_err(ci->dev, "register VBUS failed\n"); > + return ret; > + } > + } > + > + return 0; > +} > + > +static void ci_extcon_unregister(struct ci_hdrc *ci) > +{ > + struct ci_hdrc_cable *cable; > + > + cable = &ci->platdata->id_extcon; > + if (!IS_ERR(cable->edev)) > + extcon_unregister_notifier(cable->edev, EXTCON_USB_HOST, > + &cable->nb); > + > + cable = &ci->platdata->vbus_extcon; > + if (!IS_ERR(cable->edev)) > + extcon_unregister_notifier(cable->edev, EXTCON_USB, &cable->nb); > +} > + > static DEFINE_IDA(ci_ida); > > struct platform_device *ci_hdrc_add_device(struct device *dev, > @@ -921,6 +1040,10 @@ static int ci_hdrc_probe(struct platform_device *pdev) > if (ret) > goto stop; > > + ret = ci_extcon_register(ci); > + if (ret) > + goto stop; > + > if (ci->supports_runtime_pm) { > pm_runtime_set_active(&pdev->dev); > pm_runtime_enable(&pdev->dev); > @@ -938,6 +1061,7 @@ static int ci_hdrc_probe(struct platform_device *pdev) > if (!ret) > return 0; > > + ci_extcon_unregister(ci); > stop: > ci_role_destroy(ci); > deinit_phy: > @@ -957,6 +1081,7 @@ static int ci_hdrc_remove(struct platform_device *pdev) > } > > dbg_remove_files(ci); > + ci_extcon_unregister(ci); > ci_role_destroy(ci); > ci_hdrc_enter_lpm(ci, true); > ci_usb_phy_exit(ci); > diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c > index ad6c87a4653c..ab4bd0c2d4ef 100644 > --- a/drivers/usb/chipidea/otg.c > +++ b/drivers/usb/chipidea/otg.c > @@ -30,7 +30,44 @@ > */ > 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 register value > + */ > + cable = &ci->platdata->vbus_extcon; > + if (!IS_ERR(cable->edev)) { > + if (cable->changed) > + val |= OTGSC_BSVIS; > + else > + val &= ~OTGSC_BSVIS; > + > + cable->changed = false; > + > + if (cable->state) > + val |= OTGSC_BSV; > + else > + val &= ~OTGSC_BSV; > + } > + > + cable = &ci->platdata->id_extcon; > + if (!IS_ERR(cable->edev)) { > + if (cable->changed) > + val |= OTGSC_IDIS; > + else > + val &= ~OTGSC_IDIS; > + > + cable->changed = false; > + > + if (cable->state) > + val |= OTGSC_ID; > + else > + val &= ~OTGSC_ID; > + } > + > + return val; > } > > /** > diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h > index a41833cd184c..c5cddc6901d0 100644 > --- a/include/linux/usb/chipidea.h > +++ b/include/linux/usb/chipidea.h > @@ -5,9 +5,28 @@ > #ifndef __LINUX_USB_CHIPIDEA_H > #define __LINUX_USB_CHIPIDEA_H > > +#include > #include > > struct ci_hdrc; > + > +/** > + * struct ci_hdrc_cable - structure for external connector cable state tracking > + * @state: current state of the line > + * @changed: set to true when extcon event happen > + * @edev: device which generate events > + * @ci: driver state of the chipidea device > + * @nb: hold event notification callback > + * @conn: used for notification registration > + */ > +struct ci_hdrc_cable { > + bool state; > + bool changed; > + struct extcon_dev *edev; > + struct ci_hdrc *ci; > + struct notifier_block nb; > +}; > + > struct ci_hdrc_platform_data { > const char *name; > /* offset of the capability registers */ > @@ -48,6 +67,10 @@ struct ci_hdrc_platform_data { > u32 ahb_burst_config; > u32 tx_burst_size; > u32 rx_burst_size; > + > + /* 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 > -- Best Regards, Peter Chen