Received: by 10.223.185.116 with SMTP id b49csp1161241wrg; Sat, 3 Mar 2018 17:23:24 -0800 (PST) X-Google-Smtp-Source: AG47ELu0VW54SmYlE2nhlCjmyowLX5/vhjBMkI0nEanTLfwXFjfSSLEqXbxEHjuDdibFhGPb6tYB X-Received: by 2002:a17:902:c1:: with SMTP id a59-v6mr8933952pla.284.1520126604041; Sat, 03 Mar 2018 17:23:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520126604; cv=none; d=google.com; s=arc-20160816; b=MY7mpKPGuQBjEN6kvI/iVJziMbUzR3+a7NTlfpWRFCIresoOZ9MgU+CHr4Loxu5uF6 3oIVjKNKLfLM1xVFJYeNO06gY5H12R1w/EZl0Ap9HRkCoCtd+nPx1AUnd6MSXoGuFaRj 1WRt164tFvHXGdygR4JHGSogiiDv6tXZrqdsXD4RXBpda9tPWKqbDPtwAclmBCas+vW+ dMVpjA1zhw6+bPFSDRJNWHNRlzxIB05DY37C51LoBDiFVH1hKkVkm6OWm94iyUwKD4iG r4HcY4UX8LpNp9zSJBwAV3ndcwCzoKpQPStzDLpo0qDY27w7t/BRXxjZKQltRgrlWsMK DaBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=K+p1Sf5zLzlpCCXSD+1sL30cMum2ufd1Ir2s1Idg7mk=; b=xvhiLxTCf2vhI0Zottt9V15Pn2xrX0k3UPz0TjCmiB5i+3sUmrCJAYpouFKmIEtvkP v9c/e68IkUt1qRcP6RM/AUH83z6jvUMBLVrick1a8QsbUvQDFHXr7zvrrlMYaPcBeAas +FqfOsMPg6N+4p7wJGve64R9jFCbo7DfwOC6/SdQDwKsBR9PA4bxkcOSnq/GXZMWS4rr WHWUPMb/wbYfXTDej6NjG3S/CMocxAoVQwzpyRgv14EumyZF3BGsiyW0oZYfZylUTp00 JHp9ZvX9IywJCafLTdOM8DUha/kvkBYeCybWaZFglmkICvjKyY6/h0c8jexDwVcGVSv3 DkUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@adirat-com.20150623.gappssmtp.com header.s=20150623 header.b=naXFH8sS; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e5si6261665pgf.646.2018.03.03.17.22.31; Sat, 03 Mar 2018 17:23:23 -0800 (PST) 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=@adirat-com.20150623.gappssmtp.com header.s=20150623 header.b=naXFH8sS; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752026AbeCDBUn (ORCPT + 99 others); Sat, 3 Mar 2018 20:20:43 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:46184 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751756AbeCDBUm (ORCPT ); Sat, 3 Mar 2018 20:20:42 -0500 Received: by mail-wr0-f196.google.com with SMTP id m12so13707159wrm.13 for ; Sat, 03 Mar 2018 17:20:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adirat-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=K+p1Sf5zLzlpCCXSD+1sL30cMum2ufd1Ir2s1Idg7mk=; b=naXFH8sSEuHPbDrAq/K8ucMMZOyfA3393lnBlAldK880XsPmjXKC4MU71Nl84yJaRQ zsL9hXYu/7Y33mTzlCvW0BsHiex7ycEx3mXpjgF1nsMaYR6mTljEbqpJZuqEA/k7bK17 8cFhOXlbeRZWXMPQIGC7TqQ2gjVKbe/ubCiytc9j58NLZb3TnP/MAXd81ekSwOe91ylX 32XLqOz9rGkjwK40rYi3065PRsFx5XvgmHSvNKXsgEXeyQAFKOO+HhO8mTCREXDTt4EV jmn9/I6Ka5HPLKnwHBSvfYF/8af0/AAPxSossqh3/IgQA4g062YDTOYEVQ8mS2vwYJVE hb9A== 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; bh=K+p1Sf5zLzlpCCXSD+1sL30cMum2ufd1Ir2s1Idg7mk=; b=Y1VqrhsxW8pPVDwUBzjxPnO4tB3f482TO4wzUVVmiR8Sjmg9Ih/4e+ApqCnHYXvvri iYigmQCxYemsK2yACKlAdin7ZQnHFBypGgKv7UxY8T5fwSn3t4kF7ZF+bQc0u2dlz0Si 5E6LhrlEb+o5BfBny4BwTxIrVpU3DoklmyezRu7PNBNpwow3G5YTdJnjTyFh26CwTO6q sdKv+9P8XIc/MEp9RFxei8k7YY/Cy+ReZqt2cBtcb7ghscpKVqeay4lofya6zKN109Pr 9aevWmfK4SewMHwIjICgtak7GyHrH47tIj18JLq2lYwb9WFYaQtMX71X6/2YHs/J/TYT d7Xw== X-Gm-Message-State: APf1xPAT03KGy6uMssAEitnRz7BhNrixTUnJcaiJiAKa6Jf6d2iLlaYv PJI3oYZPf8fcnfGbPZcvkJPwbQ== X-Received: by 10.223.201.142 with SMTP id f14mr9052361wrh.40.1520126440829; Sat, 03 Mar 2018 17:20:40 -0800 (PST) Received: from adiPC.lan ([2a02:2f0e:190:12a9:eaa7:71e2:972d:878b]) by smtp.gmail.com with ESMTPSA id u48sm8864327wrb.85.2018.03.03.17.20.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Mar 2018 17:20:39 -0800 (PST) From: Ioan-Adrian Ratiu To: johnyoun@synopsys.com, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] usb: dwc2: detect power supplies to reduce spam Date: Sun, 4 Mar 2018 05:20:18 +0200 Message-Id: <20180304032018.12238-1-adi@adirat.com> X-Mailer: git-send-email 2.16.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org By statically hardcoding at compile time the number of supplies ("#define DWC2_NUM_SUPPLIES ARRAY_SIZE(dwc2_hsotg_supply_names)"), the driver assumed that every controller uses supplies and issued a warning if none were detected via the device tree [1], even though the vast majority of devices (with 1 exception from Samsung) don't need nor use them. So to return to normality and stop warning everyone unconditionally, detect if there are any supplies and no-op just like the dummy regulator which got loudly auto-asigned does. This issue has been previously discussed based on an alternative fix at [2] a year back but nothing came out of it then. [1] dwc2 3f980000.usb: 3f980000.usb supply vusb_d not found, using dummy regulator dwc2 3f980000.usb: 3f980000.usb supply vusb_a not found, using dummy regulator [2] https://www.spinics.net/lists/linux-usb/msg153010.html Signed-off-by: Ioan-Adrian Ratiu --- drivers/usb/dwc2/core.h | 5 +++-- drivers/usb/dwc2/platform.c | 46 +++++++++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index cd77af3b1565..c50b9fc4a162 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -128,7 +128,7 @@ static const char * const dwc2_hsotg_supply_names[] = { "vusb_a", /* analog USB supply, 1.1V */ }; -#define DWC2_NUM_SUPPLIES ARRAY_SIZE(dwc2_hsotg_supply_names) +#define DWC2_MAX_SUPPLIES ARRAY_SIZE(dwc2_hsotg_supply_names) /* * EP0_MPS_LIMIT @@ -921,7 +921,8 @@ struct dwc2_hsotg { struct phy *phy; struct usb_phy *uphy; struct dwc2_hsotg_plat *plat; - struct regulator_bulk_data supplies[DWC2_NUM_SUPPLIES]; + struct regulator_bulk_data supplies[DWC2_MAX_SUPPLIES]; + u8 num_supplies; u32 phyif; spinlock_t lock; diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index 4703478f702f..3acf658af4e9 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -126,10 +126,12 @@ static int __dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg) struct platform_device *pdev = to_platform_device(hsotg->dev); int ret; - ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), - hsotg->supplies); - if (ret) - return ret; + if (hsotg->num_supplies) { + ret = regulator_bulk_enable(hsotg->num_supplies, + hsotg->supplies); + if (ret) + return ret; + } if (hsotg->clk) { ret = clk_prepare_enable(hsotg->clk); @@ -186,8 +188,9 @@ static int __dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg) if (hsotg->clk) clk_disable_unprepare(hsotg->clk); - ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), - hsotg->supplies); + if (hsotg->num_supplies) + ret = regulator_bulk_disable(hsotg->num_supplies, + hsotg->supplies); return ret; } @@ -210,6 +213,7 @@ int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg) static int dwc2_lowlevel_hw_init(struct dwc2_hsotg *hsotg) { + struct regulator *reg; int i, ret; hsotg->reset = devm_reset_control_get_optional(hsotg->dev, "dwc2"); @@ -290,16 +294,30 @@ static int dwc2_lowlevel_hw_init(struct dwc2_hsotg *hsotg) dev_dbg(hsotg->dev, "cannot get otg clock\n"); } - /* Regulators */ - for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++) - hsotg->supplies[i].supply = dwc2_hsotg_supply_names[i]; + /* Regulators, vast majority of dwc2 devices don't use them at all */ + for (i = 0; i < DWC2_MAX_SUPPLIES; i++) { + reg = regulator_get_optional(hsotg->dev, + dwc2_hsotg_supply_names[i]); + + /* All or nothing (bulk): regs either are or aren't present */ + if (IS_ERR(reg)) { + while (--i >= 0) { + regulator_put(hsotg->supplies[i].consumer); + hsotg->supplies[i].consumer = NULL; + hsotg->supplies[i].supply = NULL; + --hsotg->num_supplies; + } + break; + } - ret = devm_regulator_bulk_get(hsotg->dev, ARRAY_SIZE(hsotg->supplies), - hsotg->supplies); - if (ret) { - dev_err(hsotg->dev, "failed to request supplies: %d\n", ret); - return ret; + hsotg->supplies[i].consumer = reg; + hsotg->supplies[i].supply = dwc2_hsotg_supply_names[i]; + ++hsotg->num_supplies; } + + WARN_ON(hsotg->num_supplies && + hsotg->num_supplies != DWC2_MAX_SUPPLIES); + return 0; } -- 2.16.2