Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp263776ybl; Thu, 15 Aug 2019 16:59:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqz09jyrpXA+efHoXro+etIkkzLAs+liOaZDVwiqND+Hl17QhVzX6VYC+gIsFF7G1iQSL7y+ X-Received: by 2002:a17:902:9889:: with SMTP id s9mr6728602plp.100.1565913563622; Thu, 15 Aug 2019 16:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565913563; cv=none; d=google.com; s=arc-20160816; b=OB17N7l91w5E6gL9p8l8fMFXPlr8HJyimEWWDwoYf3Sijubsg6HWlfq5ddWn57hDWZ fG597os7GdaFU0ybwZh24kHf4OKJy04O7kKMIUPL1C7kVOn9VAvc0wWsVM8YEHHYiIzR W2p/Uxh1K7a1FUR2K7yCpyHxJsfFYG6BL2afoM81HXoYV/dg6V0noqqoOynHl0P6dAK5 kkgu65VS6yU9lS1fJfccdtYGcF/JKKuMM27PxOxs6FZfnEzmE5UHvtY6RQCxxTuDeBra J5LBcIxc+thdvvbHvt72aSZMyFwZhdakhphkLscMLC/OY9TA0B4MPu6U6BHslYtx9KS6 ZNvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=adCOu9nDiZkMdpLyTmT0+/YcmhLlfKn9ZIk2EvNGin4=; b=NdNdZFRRlR9x8RIyMXo3YpArP4v3lTKSEMrW9NTXZIkrq3+dDGK6GZd2ITML1yV14n Z7gvJHZ+flq4mJL8RN4HAge/oYKdhJKjuQEI/uFD1YgPbiMKCsM8rTXizAZFXDl0nkNV fYhoN5ZOlDy2Ids2MmgtQ7G+rIi13otPC/IwEg4XNbzXuz5EX1/zCdW4zHrp7LFXN86O STwa8IBQscVUhQEmFWr9qBzCEA4EQ4QngwD05qIFXFTpKWIUebQxdh2jcHBjL5fY1jY7 iyHZqfRS+pgCnqOsgJMnNGFk73d8vsWwVlN/8VwyrwhcL/qP9/RVB1voNOcO3sRCyE1I 1s1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Uj64cP5/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id br21si1141530pjb.14.2019.08.15.16.59.07; Thu, 15 Aug 2019 16:59:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Uj64cP5/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726444AbfHOXmX (ORCPT + 99 others); Thu, 15 Aug 2019 19:42:23 -0400 Received: from mail-vs1-f68.google.com ([209.85.217.68]:45039 "EHLO mail-vs1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726390AbfHOXmX (ORCPT ); Thu, 15 Aug 2019 19:42:23 -0400 Received: by mail-vs1-f68.google.com with SMTP id c7so2572115vse.11 for ; Thu, 15 Aug 2019 16:42:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=adCOu9nDiZkMdpLyTmT0+/YcmhLlfKn9ZIk2EvNGin4=; b=Uj64cP5/AeOk/CghcfT2p+2nbk1bQvzFbxwrxXRumbp1HjIKC5UjhXiXj3PMo6BeTd AnqZm0zZ4O6fu8jqemv8mbSLPLQ8htWTuu9VL9CYJehnRUjUjYE0ILUP+t46sq1/QMjO nnbiw9NXBTi7lnlSt32X/XOIfMz31t7M6U5oTxXCNAwUnzsSGjl17Hi+eT1n2N2zG9II 8/MFBywmzgMh0ARxu0GQ5UrRgmoyV6rod/NVvkMmW1qWCJXm0M/5c/QDMz0JDIlwPA7I yEDQhWy7I2nGi7DCj6zEXAOdL/M+niByHpAp7hnTK2GrqGkfubUYYQR3DmWHYGx4MVtW +Y4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=adCOu9nDiZkMdpLyTmT0+/YcmhLlfKn9ZIk2EvNGin4=; b=S7lEwDVByGGtn4hJDIRXjVIliog7kP53m1FweWZo3EBzKqh46K88vOlVQwV05jtQ6D +EiLGUx/Tuc8LPw7qdx8XqiHBiOVpRfrsoHv4jP3FXDQGBbP8kaGvxruJHg8BwUQvUR1 I55asdHQLme1m8s4xWzyb8bj0IFKmEjCsOjPXMq5onTbwHZImifnByU+Y1CextS/c23B PXlm/NUR91ilkZuFHXMwHkc03V9tl2tbkcfKwm3unmw+9G/UtTQ9f1smAo1ysO5l5Dg7 8iBZE12phbozBB5eLUBkDxwhs2+tsKvXcdXRP/PH6tWHOJ2i+ymOqnazGRv8pYtdibkV 8p8A== X-Gm-Message-State: APjAAAV8qbC9ut8WYwL+dluP83pknVk/SIInCtgz+ckl5RUPwsePA0a0 KP0Ip0LVHDpBX2yiGzxs2jpEsjOQqBQqpcczooVQpg== X-Received: by 2002:a67:cd9a:: with SMTP id r26mr4589218vsl.152.1565912541342; Thu, 15 Aug 2019 16:42:21 -0700 (PDT) MIME-Version: 1.0 References: <20190813060249.GD6670@kroah.com> <20190814212012.GB22618@kroah.com> In-Reply-To: From: Duncan Laurie Date: Thu, 15 Aug 2019 17:42:05 -0600 Message-ID: Subject: Re: Policy to keep USB ports powered in low-power states To: Nick Crews Cc: linux-usb@vger.kernel.org, Enric Balletbo i Serra , linux-kernel , Daniel Kurtz , Greg Kroah-Hartman Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 14, 2019 at 6:08 PM Nick Crews wrote: > > Adding Duncan Laurie who I think has some more intimate knowledge > of how this is implemented in HW. Duncan, could you correct or elaborate > on my answers below as you see fit? Also, sorry if I make some beginner > mistakes here, I'm just getting familiar with the USB subsystem, and thanks for > your patience. > > On Wed, Aug 14, 2019 at 3:20 PM Greg Kroah-Hartman > wrote: > > > > On Wed, Aug 14, 2019 at 02:12:07PM -0600, Nick Crews wrote: > > > Thanks for the fast response! > > > > > > On Tue, Aug 13, 2019 at 12:02 AM Greg Kroah-Hartman > > > wrote: > > > > > > > > On Mon, Aug 12, 2019 at 06:08:43PM -0600, Nick Crews wrote: > > > > > Hi Greg! > > > > > > > > Hi! > > > > > > > > First off, please fix your email client to not send html so that vger > > > > does not reject your messages :) > > > > > > Thanks, should be good now. > > > > > > > > > > > > I am working on a Chrome OS device that supports a policy called "USB Power > > > > > Share," which allows users to turn the laptop into a charge pack for their > > > > > phone. When the policy is enabled, power will be supplied to the USB ports > > > > > even when the system is in low power states such as S3 and S5. When > > > > > disabled, then no power will be supplied in S3 and S5. I wrote a driver > > > > > for this already as part > > > > > of drivers/platform/chrome/, but Enric Balletbo i Serra, the maintainer, > > > > > had the reasonable suggestion of trying to move this into the USB subsystem. > > > > > > > > Correct suggestion. > > > > > > > > > Has anything like this been done before? Do you have any preliminary > > > > > thoughts on this before I start writing code? A few things that I haven't > > > > > figured out yet: > > > > > - How to make this feature only available on certain devices. Using device > > > > > tree? Kconfig? Making a separate driver just for this device that plugs > > > > > into the USB core? > > > > > - The feature is only supported on some USB ports, so we need a way of > > > > > filtering on a per-port basis. > > > > > > > > Look at the drivers/usb/typec/ code, I think that should do everything > > > > you need here as this is a typec standard functionality, right? > > > > > > Unfortunately this is for USB 2.0 ports, so it's not type-C. > > > Is the type-C code still worth looking at? > > > > If this is for USB 2, does it use the "non-standard" hub commands to > > turn on and off power? If so, why not just use the usbreset userspace > > program for that? > > It does not use the standard hub commands. The USB ports are controlled > by an Embedded Controller (EC), so to control this policy we send a command > to the EC. Since the command to send to the EC is very specific, this would need > to go into a "hub driver" unique for these Wilco devices. We would make it so > that the normal hub registration is intercepted by something that sees this is a > Wilco device, and instead register the hub as a "wilco-hub", which has its own > special "power_share" sysfs attribute, but still is treated as a normal USB hub > otherwise? > I would say it is somewhat similar to the USB port power control which eventually calls into usb_acpi_set_power_state() but in this case it only affects the behavior when the system is NOT running. This design has a standalone USB charge power controller on the board that passes through the USB2 D+/D- pins from one port and is able to do BC1.2 negotiation when the host controller is not powered, assuming the chip has been enabled by the Embedded Controller. > > > > > And how are you turning a USB 2 port into a power source? That feels > > really odd given the spec. Is this part of the standard somewhere or > > just a firmware/hardware hack that you are adding to a device? > > The EC twiddles something in the port' HW so that the port turns into a > DCP (Dedicated Charging Port) and only supplies power, not data. So I > think yes, this is a bit of a hack that does not conform to the spec. > > > > > Is there some port information in the firmware that describes this > > functionality? If so, can you expose it through sysfs to the port that > > way? > > [I'm not sure I'm answering your question, but] I believe that we could > make the BIOS firmware describe the USB ports' capabilities, and the > kernel's behavior would be gated upon what the firmware reports. I see > that struct usb_port already contains a "quirks" field, should we add a > POWER_SHARE quirk to include/linux/usb/quirks.h? I would guess that > should that should be reserved for quirks shared between many USB > devices/hubs? > We could add a Device Property to the affected USB port in ACPI and describe it that way, similar to other properties like 'vcc-supply', 'clocks', 'vbus-detect', etc and hook it into the phy-generic driver. However I'm not clear on whether the phy driver binding works with XHCI when using ACPI, so this may not be an appropriate place either. -duncan