From patchwork Mon Nov 6 22:04:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Tomsich X-Patchwork-Id: 834980 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yW6B76VKBz9s7m for ; Tue, 7 Nov 2017 09:07:43 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 97BACC21DA6; Mon, 6 Nov 2017 22:05:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 32AA7C21DC3; Mon, 6 Nov 2017 22:05:51 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D7F5BC21F27; Mon, 6 Nov 2017 22:04:53 +0000 (UTC) Received: from mail.theobroma-systems.com (vegas.theobroma-systems.com [144.76.126.164]) by lists.denx.de (Postfix) with ESMTPS id 88380C21EE6 for ; Mon, 6 Nov 2017 22:04:49 +0000 (UTC) Received: from [86.59.122.178] (port=46565 helo=android.lan) by mail.theobroma-systems.com with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA256:128) (Exim 4.80) (envelope-from ) id 1eBpVf-0008CE-K1; Mon, 06 Nov 2017 23:04:47 +0100 From: Philipp Tomsich To: u-boot@lists.denx.de Date: Mon, 6 Nov 2017 23:04:40 +0100 Message-Id: <1510005881-5519-1-git-send-email-philipp.tomsich@theobroma-systems.com> X-Mailer: git-send-email 2.1.4 Cc: Marek Vasut , Stefan Roese Subject: [U-Boot] [PATCH 1/2] usb: xhci: implement FEAT_POWER hook for switching regulators for ports X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" When the FEAT_POWER flag is set/cleared for a port, power to this port should be enabled/disabled. As many embedded xHCI controllers do not expose a signal to control this, extra effort may be required. In order to link up setting/clearing FEAT_POWER with the regulator framework (so either a regulator or a GPIO modelled as a fixed regulator) can be switched, two callbacks are implemented in this change: if regulators are available an optional property 'xhci,port-power' can contain a stringlist with names of regulators that should be switched to control the power of ports (each entry in the stringlist corresponds to its respective regulator). For some versions of the RK3399-Q7 (at least revisions v1.1 and v1.2 are affected), we need to turn on the power for the port connected to the on-module USB hub only when FEAT_POWER is set to ensure that the hub does not enter a low-power mode that U-Boot's USB stack can't deal with. Note that Linux eventually manages to attach the hub even when it's in its low-power state after a few seconds. Signed-off-by: Philipp Tomsich --- drivers/usb/host/xhci.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 4673738..dabba18 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -30,6 +30,7 @@ #include #include #include "xhci.h" +#include #ifndef CONFIG_USB_MAX_CONTROLLER_COUNT #define CONFIG_USB_MAX_CONTROLLER_COUNT 1 @@ -872,6 +873,58 @@ static u32 xhci_port_state_to_neutral(u32 state) } /** + * Switch power at an external regulator each port at the root hub, when + * the FEAT_POWER feature is set/cleared. + * + * @param ctrl pointer to the xHCI controller + * @param req_index port number as in the control message (one-based) + * @param enable boolean indicating whether to enable or disable power + * @return returns 0 on success, an error-code on failure + */ +static int xhci_board_port_powerset(struct xhci_ctrl *ctrl, int req_index, + bool enable) +{ +#if CONFIG_IS_ENABLED(OF_CONTROL) && CONFIG_IS_ENABLED(DM_REGULATOR) + /* We start counting ports at 0, while the request counts from 1. */ + int index = req_index - 1; + struct udevice *dev = ctrl->dev; + const char *regname = NULL; + struct udevice *regulator; + int ret; + + debug("%s: ctrl '%s' port %d enable %s\n", __func__, + dev_read_name(dev), req_index, enable ? "true" : "false"); + + ret = dev_read_string_index(dev, "xhci,port-power", index, ®name); + if (ret < 0) { + debug("%s: ctrl '%s' port %d: no entry in 'xhci,port-power'\n", + __func__, dev_read_name(dev), req_index); + return ret; + } + + ret = regulator_get_by_platname(regname, ®ulator); + if (ret) { + debug("%s: ctrl '%s' port %d: could not get regulator '%s'\n", + __func__, dev_read_name(dev), req_index, regname); + return ret; + } + + regulator_set_enable(regulator, enable); +#endif + return 0; +} + +static int xhci_board_port_poweron(struct xhci_ctrl *ctrl, int req_index) +{ + return xhci_board_port_powerset(ctrl, req_index, true); +} + +static int xhci_board_port_poweroff(struct xhci_ctrl *ctrl, int req_index) +{ + return xhci_board_port_powerset(ctrl, req_index, false); +} + +/** * Submits the Requests to the XHCI Host Controller * * @param udev pointer to the USB device structure @@ -1036,6 +1089,7 @@ static int xhci_submit_root(struct usb_device *udev, unsigned long pipe, xhci_writel(status_reg, reg); break; case USB_PORT_FEAT_POWER: + xhci_board_port_poweron(ctrl, le16_to_cpu(req->index)); reg |= PORT_POWER; xhci_writel(status_reg, reg); break; @@ -1056,6 +1110,7 @@ static int xhci_submit_root(struct usb_device *udev, unsigned long pipe, reg &= ~PORT_PE; break; case USB_PORT_FEAT_POWER: + xhci_board_port_poweroff(ctrl, le16_to_cpu(req->index)); reg &= ~PORT_POWER; break; case USB_PORT_FEAT_C_RESET: From patchwork Mon Nov 6 22:04:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Tomsich X-Patchwork-Id: 834982 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yW6Bf6mj5z9s7m for ; Tue, 7 Nov 2017 09:08:10 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id A2122C21F00; Mon, 6 Nov 2017 22:06:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A4805C21EF0; Mon, 6 Nov 2017 22:06:51 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 92C8EC21F49; Mon, 6 Nov 2017 22:04:55 +0000 (UTC) Received: from mail.theobroma-systems.com (vegas.theobroma-systems.com [144.76.126.164]) by lists.denx.de (Postfix) with ESMTPS id 212C7C21EF0 for ; Mon, 6 Nov 2017 22:04:51 +0000 (UTC) Received: from [86.59.122.178] (port=46565 helo=android.lan) by mail.theobroma-systems.com with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA256:128) (Exim 4.80) (envelope-from ) id 1eBpVh-0008CE-9C; Mon, 06 Nov 2017 23:04:49 +0100 From: Philipp Tomsich To: u-boot@lists.denx.de Date: Mon, 6 Nov 2017 23:04:41 +0100 Message-Id: <1510005881-5519-2-git-send-email-philipp.tomsich@theobroma-systems.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1510005881-5519-1-git-send-email-philipp.tomsich@theobroma-systems.com> References: <1510005881-5519-1-git-send-email-philipp.tomsich@theobroma-systems.com> Cc: Klaus Goger Subject: [U-Boot] [PATCH 2/2] rockchip: dts: rk3399-puma: add a 'xhci, port-power' stringlist for USB1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" USB1 is connected to the on-module USB 3.0 hub and power to the hub should be controlled via setting/clearing the FEAT_POWER flag in the root hub. This adds a 'xhci,port-power' stringlist to enable the infrastructure in xhci.c to find and control the fixed regulator associated with control of the USB hub. Signed-off-by: Philipp Tomsich --- arch/arm/dts/rk3399-puma.dtsi | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/dts/rk3399-puma.dtsi b/arch/arm/dts/rk3399-puma.dtsi index 45400fd..84b4fce 100644 --- a/arch/arm/dts/rk3399-puma.dtsi +++ b/arch/arm/dts/rk3399-puma.dtsi @@ -545,6 +545,7 @@ &dwc3_typec1 { status = "okay"; + xhci,port-power = "usbhub_enable"; }; &vopb {