From patchwork Thu Aug 6 16:02:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 11703529 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB6C913B1 for ; Thu, 6 Aug 2020 16:47:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3E7AC23119 for ; Thu, 6 Aug 2020 16:47:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aIUKmjtc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729401AbgHFQrE (ORCPT ); Thu, 6 Aug 2020 12:47:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729203AbgHFQpH (ORCPT ); Thu, 6 Aug 2020 12:45:07 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43FF1C00215E; Thu, 6 Aug 2020 09:02:52 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id i6so9906415edy.5; Thu, 06 Aug 2020 09:02:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=FNqcBw7gbdcsYAj3BqhT8zH10stbn01zoIqVBzt1ndI=; b=aIUKmjtcRfg+2LmyFEYG1ZKfDaRGWTeFidf5qZnIa7woOEXLSv/NhvJ5ESpOQxO4IZ 9MEWqCc2LNCyqR9X9i10xzsTV7daNAESKymqsWecuAPz37090vufVngrd8fK579IWdVu sibVIPxcQBqxrlx8FlQVx6IPGHSUgp7YPR1tdGSoj2P8qEOirB78nkmGpX00tvC1axQt 61EuuGL6Iu+W3cjKrZp8FbM7+hbENEgBBj9RDWxQa0xsMiQFAk95ZSPxn0GXr91S+Irj xwZDTz2R/ktqBExnTB1qryOICMOHGyUt81jv7bNAsQxX2azKJloO4Rak1vP3AaDU7i4m OyXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=FNqcBw7gbdcsYAj3BqhT8zH10stbn01zoIqVBzt1ndI=; b=SBMMBBa1OKdGYvwRWadiEPx40GloMmjD83YYQduCio1EJZmtI8wBAvrWVW2tqK36ov hT0BiCJf2LDqBPxytjHzVZnRhz6QkTFdSH71asSrp6wyfvdaTORJKodJfEQTdF6bv6/F dbubRM86QrbPyd5+lm1JthJ2GFdeEAd5O3GeKD8DIgnXOeKF4glG3/eRC+eOV0ppPKmI yLJD8BTyDOg14a5+ei9GBILRAZGMqbBj5hktq5knKpHxsPk07QGjgd3GvAkXTwfPJzTO taF+hKn+Z0OPvKKauseBR2yfP+NQkTF0dg0IW8ERdBANZklJI0OTdbdvLDD1Pq0NWpGj fX6A== X-Gm-Message-State: AOAM530W/NCdQvAGf0w5pB7i9hXEpqsybMiaBfmJfnLui6Hx/9lLu7bc wOWTw7ShLESpBtd6W6AAEmRSs0xu X-Google-Smtp-Source: ABdhPJxwDwLDDqIGo1x+XgU/Gsphj/4xYfmbRbh1sLk+5KU7qOFlfnLdw9q6QsJUuM2roZoidr6Nmg== X-Received: by 2002:a05:6402:30a5:: with SMTP id df5mr4700529edb.18.1596729771005; Thu, 06 Aug 2020 09:02:51 -0700 (PDT) Received: from localhost ([62.96.65.119]) by smtp.gmail.com with ESMTPSA id z5sm4005075ejm.111.2020.08.06.09.02.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2020 09:02:49 -0700 (PDT) From: Thierry Reding To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH 1/2] usb: common: usb-conn-gpio: Make VBUS supply optional Date: Thu, 6 Aug 2020 18:02:47 +0200 Message-Id: <20200806160248.3936771-1-thierry.reding@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Thierry Reding If the connector is the child of a USB port and that USB port already has a VBUS supply attached to it, it would be redundant to require the connector to have a VBUS supply. In this case, allow the VBUS supply to be optional. Signed-off-by: Thierry Reding --- drivers/usb/common/usb-conn-gpio.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/usb/common/usb-conn-gpio.c b/drivers/usb/common/usb-conn-gpio.c index 7b3a21360d7c..c5b516d327c7 100644 --- a/drivers/usb/common/usb-conn-gpio.c +++ b/drivers/usb/common/usb-conn-gpio.c @@ -91,14 +91,14 @@ static void usb_conn_detect_cable(struct work_struct *work) return; } - if (info->last_role == USB_ROLE_HOST) + if (info->last_role == USB_ROLE_HOST && info->vbus) regulator_disable(info->vbus); ret = usb_role_switch_set_role(info->role_sw, role); if (ret) dev_err(info->dev, "failed to set role: %d\n", ret); - if (role == USB_ROLE_HOST) { + if (role == USB_ROLE_HOST && info->vbus) { ret = regulator_enable(info->vbus); if (ret) dev_err(info->dev, "enable vbus regulator failed\n"); @@ -106,8 +106,9 @@ static void usb_conn_detect_cable(struct work_struct *work) info->last_role = role; - dev_dbg(info->dev, "vbus regulator is %s\n", - regulator_is_enabled(info->vbus) ? "enabled" : "disabled"); + if (info->vbus) + dev_dbg(info->dev, "vbus regulator is %s\n", + regulator_is_enabled(info->vbus) ? "enabled" : "disabled"); power_supply_changed(info->charger); } @@ -156,6 +157,7 @@ static int usb_conn_probe(struct platform_device *pdev) struct power_supply_config cfg = { .of_node = dev->of_node, }; + bool need_vbus = true; int ret = 0; info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); @@ -185,7 +187,23 @@ static int usb_conn_probe(struct platform_device *pdev) INIT_DELAYED_WORK(&info->dw_det, usb_conn_detect_cable); - info->vbus = devm_regulator_get(dev, "vbus"); + /* + * If the USB connector is a child of a USB port and that port already provides the VBUS + * supply, there's no need for the USB connector to provide it again. + */ + if (dev->parent && dev->parent->of_node) { + if (of_find_property(dev->parent->of_node, "vbus-supply", NULL)) + need_vbus = false; + } + + if (!need_vbus) { + info->vbus = devm_regulator_get_optional(dev, "vbus"); + if (PTR_ERR(info->vbus) == -ENODEV) + info->vbus = NULL; + } else { + info->vbus = devm_regulator_get(dev, "vbus"); + } + if (IS_ERR(info->vbus)) { if (PTR_ERR(info->vbus) != -EPROBE_DEFER) dev_err(dev, "failed to get vbus\n"); @@ -266,7 +284,7 @@ static int usb_conn_remove(struct platform_device *pdev) cancel_delayed_work_sync(&info->dw_det); - if (info->last_role == USB_ROLE_HOST) + if (info->last_role == USB_ROLE_HOST && info->vbus) regulator_disable(info->vbus); usb_role_switch_put(info->role_sw); From patchwork Thu Aug 6 16:02:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 11703479 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2B0631392 for ; Thu, 6 Aug 2020 16:27:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 78A9023119 for ; Thu, 6 Aug 2020 16:27:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Z1PLwnz5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727864AbgHFQ1j (ORCPT ); Thu, 6 Aug 2020 12:27:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727081AbgHFQSr (ORCPT ); Thu, 6 Aug 2020 12:18:47 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 283EBC00215F; Thu, 6 Aug 2020 09:02:55 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id v22so24751828edy.0; Thu, 06 Aug 2020 09:02:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CECQrTdPbGjVPX2RCRIk8am23VvwhZ+qTSo0hSxBl3o=; b=Z1PLwnz5/fx/Z6dzRP3Qg8AStjfCJB6bxY4Q5BbC/Wgxs6E3gpE97VG8FbsJpxuY2M zVCfl8kTqJRQXVsI3XcAbbohpxUXhB2pQ7arkm8ajmV6xCaMGQ7S+gD+MhJ034iLfQf9 MqVmtVLiytju3ZSHmh5wEFSn7QcM67A+xj5w+xe0sZe42IwZZjUIy0jto/NFTWpOQJZn ndREU01ar4OvfUT0osHmTkDB3zXoCxiNdboAkApDBwcsJbBBjCYTjIPm0oFlIsJZiPYz kz6HqUpuaFjwe/lhWxNOpTSoOyhVVNjQ3Jx0FU8vg/cVAzvmJUj8jEXNpYz68nzZhXQQ qOBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CECQrTdPbGjVPX2RCRIk8am23VvwhZ+qTSo0hSxBl3o=; b=HBCbEhqRFfnYDLTioCYQ/yRIbj/fME6zlxKeKBuxxIkh8anpNciiNIUNdvrp9rr6T9 +BMWLsp6864ET5jKZAmk4bcMxG+tgUiAd2bIXNe9NyZjMcs/6MsjkYgSgW0gzoYLdlk7 yUaGsCLENbLPa9QZE9IFqS57A98gmERqwNNXnqdb1w414KKDerUfVwgo1fnVp8TZblnt 4cizhUHKTv0HbxLQxqyhYr099WyCtl8sS+f+UUJvsnkhWZekybGApVvkZxPvENxJtKSw 80tIq6z5r6Bb9CJE9qBb2du5HJGx9dfwmzDr2QE7c5PP5fRcU/kBIJaEJh2FGPX0FVvi SIYA== X-Gm-Message-State: AOAM531pZA0ujs3RHll8khEMbBl8UgCx77ASJ7IaHlk+hJyaCDt2Z2FU PtDE0GMa/0161y8KNKiPUOA= X-Google-Smtp-Source: ABdhPJyjP6Tg6vGResi/PT4q25in8ESFmnFaAbhMRGP9vNUEC8yre8RyUHGTeEb31y1gXCLySX9zDQ== X-Received: by 2002:a50:d908:: with SMTP id t8mr4558574edj.373.1596729773914; Thu, 06 Aug 2020 09:02:53 -0700 (PDT) Received: from localhost ([62.96.65.119]) by smtp.gmail.com with ESMTPSA id a16sm4011063ejy.78.2020.08.06.09.02.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2020 09:02:52 -0700 (PDT) From: Thierry Reding To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH 2/2] usb: common: usb-conn-gpio: Print error on failure to get VBUS Date: Thu, 6 Aug 2020 18:02:48 +0200 Message-Id: <20200806160248.3936771-2-thierry.reding@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200806160248.3936771-1-thierry.reding@gmail.com> References: <20200806160248.3936771-1-thierry.reding@gmail.com> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Thierry Reding The exact error that happened trying to get the VBUS supply can be useful to troubleshoot what's going on. Signed-off-by: Thierry Reding --- drivers/usb/common/usb-conn-gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/common/usb-conn-gpio.c b/drivers/usb/common/usb-conn-gpio.c index c5b516d327c7..6c4e3a19f42c 100644 --- a/drivers/usb/common/usb-conn-gpio.c +++ b/drivers/usb/common/usb-conn-gpio.c @@ -206,7 +206,7 @@ static int usb_conn_probe(struct platform_device *pdev) if (IS_ERR(info->vbus)) { if (PTR_ERR(info->vbus) != -EPROBE_DEFER) - dev_err(dev, "failed to get vbus\n"); + dev_err(dev, "failed to get vbus: %ld\n", PTR_ERR(info->vbus)); return PTR_ERR(info->vbus); }