Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752596AbbFEJoR (ORCPT ); Fri, 5 Jun 2015 05:44:17 -0400 Received: from mail-by2on0117.outbound.protection.outlook.com ([207.46.100.117]:7344 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750878AbbFEJoN (ORCPT ); Fri, 5 Jun 2015 05:44:13 -0400 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: Fri, 5 Jun 2015 17:26:46 +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 v3] usb: chipidea: Use extcon framework for VBUS and ID detect Message-ID: <20150605092645.GJ15169@shlinux2> References: <1433250873-20780-1-git-send-email-ivan.ivanov@linaro.org> <20150605070332.GI15169@shlinux2> <1433489827.6540.0.camel@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <1433489827.6540.0.camel@linaro.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD030;1:QFEqdEkL6lbAfF8ggfZSziUMRuCDnxELO0SBzrP8kiJ4elsMvq4AYoVsNjzYGuhXDu8/wsOV0M9JPXC0DVXXGSQEOBZSFsWGmuu776HUavNYTaPvWukEKfpagnowAjjMztVUOPL/laqerA7aDzFDh393qX+8o5vMTvxixhI+IeIOGKpdgd+5RaXhCuoUrP0MmZ6kOI7g4/qezBzNK8OiZzetKQ8nZBb1EgxtkPBB4DcKG2aV8OTbMCbse2gQeP5xOpRmsHTL8flUPZY0IVt106mg2bYQ9Z1FlT6j6JLfE9sQxKTaM+nYf0RSa8S5/WSGdiubLFqqAf91vjgu7ml66Q== X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(339900001)(24454002)(199003)(51704005)(377424004)(189002)(33716001)(104016003)(50466002)(47776003)(83506001)(6806004)(19580405001)(85426001)(23726002)(46102003)(19580395003)(106466001)(76176999)(54356999)(46406003)(87936001)(97756001)(86362001)(50986999)(92566002)(77156002)(62966003)(33656002)(4001350100001)(189998001)(110136002)(5001960100002)(105606002)(77096005)(2950100001);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR03MB278;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;MLV:sfv;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB278;2:Ohonm9Smm2zNAPNkRixIrsuzWVjtL+Uej/suW+vzN8PNKYP/DMg7+wzOjL8KOIpd;2:YnXRyLy4JWxEcqthy9H6Wb6IVNcIttd58x8Pay72Sj+1wBpZHPirDJGyA5OUzpyD+xMViuDyWQu48cWxnRZxqEtrisnJlCXcL32gN2nZnQBRO3oTNuLbPKqgzxMDxVePUYN2p/GDXDFIIx0db9lrsSCQ0tqahPPoJaCabGaJu6dTbJ50IE8D9/pB7lH/p9Voxw1Fyg7gGw6k8OkjeVUm00yPRwzZgs8HSwOeus8OYYE=;6:pMCA3Lz856NxDW+CFeNizCR9O3xghepPPNOH3wzfOmTvjzekpzd+AkR/F5s7eKQMzBBvtvpzVix1lWXX4S9AyAuxl43pd+EMEr4m4HUzJ6oOYsKnzMfzqTqJE2qq9ppO6QOMJ5vGcBrD6Y67jmbHyjd3D83MMvHt/09Slj2sYBc0vGouUhiHGPRokq4GklAjG4w/fVDZTqf2OjtTmYfYHdu5qChaqlPiGZsupbKHcd96tPP0u2GEfT7lZpjbksC7jzPIIe/VAUYoEb3VkOse+8xTEnd2PuS1yA6wPALEDNoK2RC++QwUhMXpsp3y+ZxUZaTY+cc8mz9W+ds4nL+jyg==;3:/YCtdybCwBi6jbCeXHsMUz6LVT/670xmq/I4zWBLRvOsWq0mwn4+YqM16OzId96/uWOZ4YalLfquPtYJbvBat8Tiac+13iwRKZvWCvTGw9kK6vIRAMSkUert389F2erWkXJVlXvF2lnac5OWGV0M4fQ/LhgWEvBdG7/eX1lNR9+ScOuPnfGFYe5O5laboG+TEYvpoJzDbrDhkpXN3twD/MU+SNsfa+tOBGpV7njRqzzr8nNkptVmVl82rTAA7u9bK5BwWOxoeSGul63Pt8GAotiinIyoJAYME91KcMQ6cuwPLSa7XrcevhSMTUv4ckG2 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB278; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(520003)(3002001);SRVR:BLUPR03MB278;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB278; X-Forefront-PRVS: 05986C03E0 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BLUPR03MB278;9:0G7H2/p5dXlA0g27qBy3Fp0x+R4XaV5DEMmAeKHATob?= =?us-ascii?Q?X/gNr6Lx6GBJ2KmbwtOndEBtFfWtiL4s0YJBWXytY4Ig3bfWxV2isj7duhwx?= =?us-ascii?Q?ZPMdSSQKy8GX0ZoC7Mgdb04bgTQmYZ3bJhk/wtjBL2TWY5rXDfolSq2J4/QI?= =?us-ascii?Q?XvgA+0dk/iBvdrGfjTp7JSGyYSL2IxClBpS97C1zMsYX4bgdHRec6TDs2khN?= =?us-ascii?Q?lG28OqOOVNS88zimuezd0wwMTQdwFOwoK11ADy5IlLf+8k9Mo3YpuzSHGF4v?= =?us-ascii?Q?s6IrY9rSIh2oUWNEDKCEiTGmCqbNySQd1N39hP4qz6tSFHRM+a67E7MOcmmi?= =?us-ascii?Q?aRowIMckEWlSW3SEKiUTeRx+QA/WjSeBOTUq61RH60Wkq3+FYbMiLSwloy6f?= =?us-ascii?Q?ICN1f+VMjE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-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jun 2015 09:28:17.0546 (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: BLUPR03MB278 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 13201 Lines: 374 On Fri, Jun 05, 2015 at 10:37:07AM +0300, Ivan T. Ivanov wrote: > > On Fri, 2015-06-05 at 15:03 +0800, Peter Chen wrote: > > On Tue, Jun 02, 2015 at 04:14:33PM +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 ivanov@linaro.org> > > > --- > > > Changes sice v2 [1]. > > > > > > * Simulate IRQ on extcon event - used to trigger OTG state machine. > > > > > > > No, you may not need to trigger complicate OTG FSM, instead, the > > role switch based on ID value is ok. > > I have tried this also, but I decided that using IRQ simulation > will handle all use cases. > After thinking more, I agree this solution > > > > > I have to admit that I couldn't test complete Chipidea OTG state machine, > > > because my setup is little weird. I am using "qcom,usb-otg-ci" as PHY/OTG > > > provider, "qcom,ehci-host" as host controller driver and "qcom,ci-hdrc" for > > > device role. > > > > > > > Then, I am puzzled what kinds of flow you have tested in this patch? > > extcon is really needed for chipidea core, but I hope we have tested > > patch set based on it. Rob Herring have tested Marvell's host controller > > can also use chipidea host driver, I think the same for qualcomm's. > > The otg flow at phy-msm-usb.c can be removed and use chipidea's instead, and > > only remain phy part at it. > > I have tried this, but there is too many legacy code which is supposed to > handle old platforms and I can not distinguish, which should stay in and > what could be taken out. I will take a look again. > Yeah, you can test your own patch. > > > > Current role switch and vbus flow are based on otgsc register, you can > > improve it by adding extcon support. > > I am not sure that I get this. Isn't exactly what this patch does? > Yes, you are right, see my further comments for your patch. > > > > > > +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; > > > + How to know the id value must be changed? How about using id->changed = (event != id->state) ? true : false? of cos, it needs to move before if {}. The same change may need to add to vbus notifier. > > > + 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) > > > platdata->phy_mode = of_usb_get_phy_mode(dev->of_node); > > > > > > @@ -591,9 +630,89 @@ 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); > > > + } > > > + > > > + 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, "USB"); I have not read extcon framework too much, but seems you should only can get cable state after register it (through ci_extcon_register)? ci_get_platdata is called before ci core probe. > > > + 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, "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_interest(&id->conn, id->edev->name, > > > + "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_interest(&vbus->conn, vbus->edev->name, > > > + "USB", &vbus->nb); > > > + if (ret < 0) { > > > + extcon_unregister_interest(&id->conn); > > > + 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_interest(&cable->conn); > > > + > > > + cable = &ci->platdata->vbus_extcon; > > > + if (!IS_ERR(cable->edev)) > > > + extcon_unregister_interest(&cable->conn); > > > +} > > > + > > > static DEFINE_IDA(ci_ida); > > > > > > struct platform_device *ci_hdrc_add_device(struct device *dev, > > > @@ -817,6 +936,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); > > > @@ -834,6 +957,7 @@ static int ci_hdrc_probe(struct platform_device *pdev) > > > if (!ret) > > > return 0; > > > There is dbg_create_files between these code which may also fail. > > > + ci_extcon_unregister(ci); > > > stop: > > > ci_role_destroy(ci); > > > deinit_phy: > > > @@ -853,6 +977,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 ad6c87a..77fe2df 100644 > > > --- a/drivers/usb/chipidea/otg.c > > > +++ b/drivers/usb/chipidea/otg.c > > > @@ -30,7 +30,41 @@ > > > */ > > > 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 > > > + */ %s/resiter/register > > > + cable = &ci->platdata->vbus_extcon; > > > + if (!IS_ERR(cable->edev)) { > > > + if (cable->changed) > > > + val |= OTGSC_BSVIS; > > > + else > > > + val &= ~OTGSC_BSVIS; > > > + > > > + if (cable->state) > > > + val |= OTGSC_BSV; > > > + else > > > + val &= ~OTGSC_BSV; > > > + } You can clear cable->changed after that, then no change for hw_write_otgsc is needed. > > > + > > > + cable = &ci->platdata->id_extcon; > > > + if (!IS_ERR(cable->edev)) { > > > + if (cable->changed) > > > + val |= OTGSC_IDIS; > > > + else > > > + val &= ~OTGSC_IDIS; > > > + > > > + if (cable->state) > > > + val |= OTGSC_ID; > > > + else > > > + val &= ~OTGSC_ID; > > > + } > > > + > > > + val &= mask; It seems you do not need to do &mask again. > > > + return val; > > > } > > > > > > /** > > > @@ -40,7 +74,24 @@ u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask) > > > */ > > > void hw_write_otgsc(struct ci_hdrc *ci, u32 mask, u32 data) > > > { > > > - hw_write(ci, OP_OTGSC, mask | OTGSC_INT_STATUS_BITS, data); > > > + struct ci_hdrc_cable *cable; > > > + > > > + mask |= OTGSC_INT_STATUS_BITS; > > > + > > > + /* clear artificial bits */ > > > + cable = &ci->platdata->vbus_extcon; > > > + if (!IS_ERR(cable->edev)) { > > > + if (data & OTGSC_BSVIS) > > > + cable->changed = false; > > > + } > > > + > > > + cable = &ci->platdata->id_extcon; > > > + if (!IS_ERR(cable->edev)) { > > > + if (data & OTGSC_IDIS) > > > + cable->changed = false; > > > + } > > > + > > > + hw_write(ci, OP_OTGSC, mask, data); > > > } > > > > > > /** > > > diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h > > > index ab94f78..05915cb1 100644 > > > --- a/include/linux/usb/chipidea.h > > > +++ b/include/linux/usb/chipidea.h > > > @@ -5,9 +5,29 @@ > > > #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_blocknb; > > > + struct extcon_specific_cable_nb conn; > > > +}; > > > + > > > struct ci_hdrc_platform_data { > > > const char*name; > > > /* offset of the capability registers */ > > > @@ -35,6 +55,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_cablevbus_extcon; > > > + struct ci_hdrc_cableid_extcon; > > > }; > > > > > > /* Default offset of capability registers */ > > > -- > > > 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/