Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756513AbbGTIZd (ORCPT ); Mon, 20 Jul 2015 04:25:33 -0400 Received: from mail-bl2on0113.outbound.protection.outlook.com ([65.55.169.113]:30869 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756030AbbGTIZZ (ORCPT ); Mon, 20 Jul 2015 04:25:25 -0400 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; google.com; dkim=none (message not signed) header.d=none; Date: Mon, 20 Jul 2015 15:15:56 +0800 From: Peter Chen To: Sumit Semwal CC: Felipe Balbi , "linux-kernel@vger.kernel.org" , Greg Kroah-Hartman , "linux-usb@vger.kernel.org" , Android Kernel Team , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Benoit Goby , Todd Poynor Subject: Re: [PATCH v3 3/3] usb: phy: hold wakeupsource when USB is enumerated in peripheral mode Message-ID: <20150720071555.GA5715@shlinux2> References: <20141125144544.GC6360@saruman> <20150113161802.GD16533@saruman> <20150114012653.GB14944@shlinux2> <20150608083152.GB6743@shlinux2> <20150713070002.GA12197@shlinux2> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD003;1:2ueUJFsEary8sAIu1cCOEaEC3TEJu6mvwVMxgExC0hbLt6QhINYeQgoNXlhbcbJI6cCi6hs0C8q8yJHCOBtNTV/WL7BTiV2SWPU4GSEEFfbgYKKl8Z+YbdiLr6XgN5mE0ImsEhjbzbNYjZJdJBF92IP4qRTsPnfUMI4WCp00nsmYnWWv+5u+WCgbuV4wS3z7Vhog56ZkPa6vwMOZHleItfs3zYMUQpJeiEx/cZQt8wIdY6XKrBqHT26DKrJkU7YxKwKxuOWNkTidNw50DURmgzqFT3V/bVvcb42d9zLg+ysk1dgoEJ4mv0V9gjo8ZzSlv8McaKijOwALV4PVvYmDBlysRRl9/KeGM9dyS6RAjahyDJIO/bnwLyYAQvPETLwT05rlWOBUz19BT//UPzNQx4zVPMsuveSApjvn/R73j74= X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(339900001)(69224002)(189002)(199003)(24454002)(104016003)(62966003)(76176999)(93886004)(46406003)(33656002)(33716001)(50986999)(85426001)(54356999)(2950100001)(46102003)(97756001)(105606002)(19580405001)(92566002)(189998001)(4001350100001)(5001920100001)(86362001)(50466002)(77156002)(83506001)(19580395003)(87936001)(77096005)(5001960100002)(106466001)(47776003)(110136002)(23726002)(6806004);DIR:OUT;SFP:1102;SCL:1;SRVR:CH1PR03MB612;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;MLV:sfv;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;CH1PR03MB612;2:UglR2QtaO5dxcCr7Tnf9pF85+is9A7J2efJn+5qvSAGM5N3uDhX6375/gDlFc3JI;3:9sP881LX+U8g8c4UUH+j21Zmw7njjzMwsOGj3GFLrFj7+1tCKglNvWPlDCPNy6yqMlLMLh8fF9kqD+wXZAuWNeWYjfXpWmuzTe0gnQ0PiTWAmBsF5VP1WF+TMsrwePDSbXdFrwlHot7prxVA5qMLCWR7E+wMJ/5kyNCbUbEKU6QHIOZMu2n2d+9bBhL5xrAZMW8bH+LuI14toDIe2m7bEqcOW6fo+6XuWbJtJnThq2o=;25:lYyrVc+hPpa99JYZFU7Ary9Ei1xjS95cRj3x2KDUpTX83OMlHE3j5uFiznclWM7n2masTV2se4mPwVvWlg5BAeFLKodnjHphnI4Wnu82M0khk1UTHwAYgaBkH3QyHZeiAeKKSQ9p2TjFRUNMQL54wGOafTNpvy/S7muSfGhkYx9lZe+HepNkZ9behQSdlQA/qM6y8U70l5eU9FfS4y4OwJKT1NhxIn0jsbZOX4D58lEMJgvZDcnWINghaTGXfeMiPpdd7yg0m7GUqf2NoMBU8Q==;20:8m44bG4IHykKBMcaVlmffJDzVPRmN5y1j4637ntbY9Klm17eGHb77GT+rSICfILP58NzaIwRfXDZGiNzbug2kVVL3Q22gVu8FxoWlosIZBKER/CXOnjB+F7gBN1N/STg2BquHol9qvwG2leif33wV32XnuEu/cdgaTZRqC2nMeF67XoQ/rNgK7LjVbciPi6glmOTnL1edTN5QMGnKoX8l0GYo/2NKb6npki21c6zCY+0807pD7riygmfEhXBu+/qmi9OHJOBsq7Q/qFAUN9xkQf4XGzqfc9JKZw8ROiCZTDpPRiKbqPIcrdlbAUsXzb1zHVWRalvz+ZOkXFo4mxAwE5LEYxpbB08f8+/Rw0jxyQ= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CH1PR03MB612; CH1PR03MB612: X-MS-Exchange-Organization-RulesExecuted X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:CH1PR03MB612;BCL:0;PCL:0;RULEID:;SRVR:CH1PR03MB612; X-Microsoft-Exchange-Diagnostics: 1;CH1PR03MB612;4:JYckj1gH2fNma/cwEUdmi7giprjq2Ja+QljSUjVRXA33UxwuE4tuYjcOahoT4WhJzPXnBtZ/Q+ut5n9GI4oLMwgbm3cfUFA7RR3Tp6OXenH+jacWqEuzLJ4FJIItMrgAKOTSeNNwdd7BuQMCvF8LJr7d4VUSbadZc89vv2BBmCdcad+VS17dVKupYQCkYIP7Ue6KqV6HjGFshQfF286FzmljN6GPZQHt+Tu4bMbuotq0f/nTn/WKj6Z00rCRg4+f3Gc8tSnPz3s1QYGRQ69X1pKjbJYuPw0TUSIPpiXSMHg= X-Forefront-PRVS: 0643BDA83C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CH1PR03MB612;23:0bH142xyz+0soaAjIxCMEiVEx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Y3KCy08A/udEGAHLqyV6otJ1L4ky+ZJ5WOQydKyOy2hgJ?= =?us-ascii?Q?Ax7E+Ub639qxuyGM2fGM+N2huXq9yrgUo1rDBCK9wo5W6Ryu6VyjffyvQ0wY?= =?us-ascii?Q?nlZRLO8V/W/SvyVm1PV81IMQjyNMWBllOhGa+nGkzH2A=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;CH1PR03MB612;5:0LspUYQXHe2dCXznvo0IgTRuslART+kvdAAjkFnRaFT9sn9jx++1QQgDYIRps8VYWQDhn4EQYitcyyHpeKbn4S8/yPX2VLaMMBt+esruPmMwVIJ+J+C227W1GhjODas6L+xGA4VDhqfQSV67YPsoug==;24:BfjZKich/yLsa2QufcftjKGtzinXLdjVLm4bMHh2AWOsEIr/FSsczNxSf4+GicQ/Dqhj+cxJLjDZikkXqdQRb3lfRhhpr/Dudio7iQ6UhW0=;20:FEsI8jZxpPrvi+UqBcV2gIcp8R0Mb8bsamOkRltmGK4IavgSdGuEVg6XfZyxKz3pqe5NbWcAQdt6XB0h/1sn/A== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2015 08:25:22.9181 (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: CH1PR03MB612 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4957 Lines: 118 On Mon, Jul 20, 2015 at 01:18:35PM +0530, Sumit Semwal wrote: > On 13 July 2015 at 12:30, Peter Chen wrote: > > On Mon, Jul 13, 2015 at 01:26:23PM +0530, Sumit Semwal wrote: > >> Hi Peter, > >> > >> On 8 June 2015 at 14:02, Peter Chen wrote: > >> > On Mon, Jun 08, 2015 at 12:37:00PM +0530, Sumit Semwal wrote: > >> >> H Peter, Felipe, > >> >> > >> >> On 14 January 2015 at 06:56, Peter Chen wrote: > >> >> > On Tue, Jan 13, 2015 at 10:18:02AM -0600, Felipe Balbi wrote: > >> >> >> On Tue, Jan 13, 2015 at 04:02:20PM +0530, Kiran Raparthy wrote: > >> >> >> > Hi Felipe, > >> >> >> > > >> >> >> > On 1 December 2014 at 11:09, Kiran Raparthy wrote: > >> >> >> > > Hi Felipe, > >> >> >> > > > >> >> >> > > On 25 November 2014 at 20:15, Felipe Balbi wrote: > >> >> >> > >> On Tue, Nov 25, 2014 at 07:06:18AM +0000, Peter Chen wrote: > >> >> >> > >>> > >> >> >> > >>> > > >> >> >> > >>> > usb: phy: hold wakeupsource when USB is enumerated in peripheral mode > >> >> >> > >>> > > >> >> >> > >>> > Some systems require a mechanism to prevent system to enter into suspend > >> >> >> > >>> > state when USB is connected and enumerated in peripheral mode. > >> >> >> > >>> > > >> >> >> > >>> > This patch provides an interface to hold a wakeupsource to prevent suspend. > >> >> >> > >>> > PHY drivers can use this interface when USB is connected and enumerated in > >> >> >> > >>> > peripheral mode. > >> >> >> > >>> > > >> >> >> > >>> > A timed wakeupsource is temporarily held on USB disconnect events, to allow > >> >> >> > >>> > the rest of the system to react to the USB disconnection (dropping host > >> >> >> > >>> > sessions, updating charger status, etc.) prior to re-allowing suspend. > >> >> >> > >>> > > >> >> >> > >>> > >> > >> >> > >> >> Kiran is unable to continue on this patch anymore, so despite my very > >> >> limited usb experience, I would like to take this over and with your > >> >> help, take it to closure. > >> >> > >> >> From what I understand, it might be possible to do this either at the > >> >> usb controller driver (where it detects if it has enumerated in host > >> >> mode or device mode) or in the extcon driver (where it detects VBUS > >> >> etc..) - which would be a cleaner / more logical way to do it? > >> >> > >> >> Thanks for all your help! > >> > > >> > I added my suggestions below: > >> > > >> > My opinion is: if we need this feature, we should depend on gadget's > >> > state, eg 'configured', not vbus level. The system suspend should be > >> > allowed if the gadget state is 'suspended' even vbus is still there. > >> > > >> > And when the gadget goes to suspend or reset or disconnect state, we can > >> > go to disable this wakeup source. > >> > > >> > At drivers/usb/gadget/composite.c, we can know the gadget's state. > >> > > >> Thanks very much for your suggestion, and apologies in the delay in response. > >> > >> I tried to study your suggestion and the code a little bit more, and > >> while I liked your idea quite a bit, I also realised that for the case > >> of letting the USB charger use cases, in gadget framework, there > >> doesn't seem to be a way to get the USB_EVENT_CHARGER, since charger > >> would likely not be a gadget. > >> > >> In this case, how'd we be able to enable / disable wakeup_source for > >> charger events? > > > > We may not prevent the system entering system if it is a charger, isn't > > it, so don't need to consider USB charger. > > > Thanks for your comments, Peter! > From the Android code that I see, it seems that for a charger > connect/disconnect, some systems might require some time to react to > the change in power, and hence there's a timed-out wakeup event for > USB charger cases. That;s where the consideration for USB chargers > came from. Current udc core has an API usb_gadget_set_state set its state according to usb ch9. For this wakeup source case, if the peripheral has been configured, it can hold wakeup source. Otherise, just have a timeout wake lock. Below are some reference code: diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c index d69c355..018f534 100644 --- a/drivers/usb/gadget/udc/udc-core.c +++ b/drivers/usb/gadget/udc/udc-core.c @@ -136,6 +138,16 @@ static void usb_gadget_state_work(struct work_struct *work) if (udc) { sysfs_notify(&udc->dev.kobj, NULL, "state"); switch (gadget->state) { case USB_STATE_CONFIGURED: __pm_stay_awake(&x->wsource); break; default: __pm_wakeup_event(&x->wsource, USB_DEFAULT_WAKEUP_SRC_TIMEOUT); break; } } -- 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/