Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
From: Duncan Laurie <dlaurie@google.com>
To: Nick Crews <ncrews@chromium.org>
Cc: linux-usb@vger.kernel.org,
	Enric Balletbo i Serra <enric.balletbo@collabora.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Daniel Kurtz <djkurtz@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: Policy to keep USB ports powered in low-power states
Date: Thu, 15 Aug 2019 17:42:05 -0600
Message-ID: <CADv6+07pYd-kg1i0TJXOPnEO6NUp6D5+BQBkqUO0MDAE+cquow@mail.gmail.com> (raw)
In-Reply-To: <CAHX4x84YM0PcoQw17FxMz=6=NPq2+HUUw2GWZarAKzZxr+ax=A@mail.gmail.com>

On Wed, Aug 14, 2019 at 6:08 PM Nick Crews <ncrews@chromium.org> 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
> <gregkh@linuxfoundation.org> 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
> > > <gregkh@linuxfoundation.org> 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
> > > > > <https://lore.kernel.org/patchwork/patch/1062995/> 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

  reply index

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAHX4x86QCrkrnPEfrup8k96wyqg=QR_vgetYLqP1AEa02fx1vw@mail.gmail.com>
2019-08-13  6:02 ` Greg Kroah-Hartman
2019-08-14 20:12   ` Nick Crews
2019-08-14 21:20     ` Greg Kroah-Hartman
2019-08-15  0:08       ` Nick Crews
2019-08-15 23:42         ` Duncan Laurie [this message]
2019-08-16  9:12           ` Greg Kroah-Hartman
2019-08-16 17:02             ` Duncan Laurie

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADv6+07pYd-kg1i0TJXOPnEO6NUp6D5+BQBkqUO0MDAE+cquow@mail.gmail.com \
    --to=dlaurie@google.com \
    --cc=djkurtz@google.com \
    --cc=enric.balletbo@collabora.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=ncrews@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org linux-usb@archiver.kernel.org
	public-inbox-index linux-usb


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/ public-inbox