Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5787440ybv; Tue, 11 Feb 2020 23:56:10 -0800 (PST) X-Google-Smtp-Source: APXvYqzlI+zukoWs9oFh0eQrVJ/SllT78lyeCpb4g8IR3/yvyD6a+oZY7WbEMW/KBjHokNJwOHIG X-Received: by 2002:aca:56ce:: with SMTP id k197mr5644897oib.99.1581494170386; Tue, 11 Feb 2020 23:56:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581494170; cv=none; d=google.com; s=arc-20160816; b=wcKJvxQy/pGiYaGRoj1YgSab19Ukks2iL78PIsHg5Il+H6ugS77saFIbEyAohFVIbs mOHYg0mfjajTeTpDCS2VK8qbBchVzY5xjWnXz2dTYE/ElUCL3odsfgJBy2QScSEsbGT2 Vswm+0aayGntfrV5U2PxmHyTWOM/p4moqYwHoDrFyoHCu5nVNf1d2tg768KcNwDBsNS/ 7n2OhQ0nMj7Xz6P+q9y2hB+4ZaOTx6XMHd7nU15bvdKD6zG3Ku050yQ+DIROtT3t4425 b7k2McrmNQt4o3jwVv0rWkogxLbsDGe8zLNWUoBWrYKr5RwAibm5ZRAVG92JD3890M9y pvtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=VF571MMcb1F1isbPRkdGPyOV5FtumBnPxlJ+7Ql/2kk=; b=OYN447tCBcT2CB/7yhp3qAnDdQ5hlXOW2f+4E9WuUdYhPRa1rDyNapaBpAU+k8b9Jj 9ccoznvWAYc4WIkT/ErajpFlDAXafZNHsSxEpeuVZibLUc4vNR61xvV/zi9JzgTiYxqI h8Hf/H/69noQoZobXK2we/giwf2STJ1vA5A2jnCMjZr9kGR1tdTXf7abs1snvtb+w/7g huMdRgkXGrJeSUNMJxHEUl2rDqHZzeh4DyaXGoYh5xhx7Y8FWl5eG6fcovsvJ7b7ubqT bAJNZoiNQErlgBzncWd1KdoPJyG8C+3reP1SDibQCF2jWd8plR5dNliZvUGd15pYAUE6 c7dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=M8jzit6j; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 107si3295405oth.14.2020.02.11.23.55.57; Tue, 11 Feb 2020 23:56:10 -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=@chromium.org header.s=google header.b=M8jzit6j; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728393AbgBLHze (ORCPT + 99 others); Wed, 12 Feb 2020 02:55:34 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:39047 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728381AbgBLHze (ORCPT ); Wed, 12 Feb 2020 02:55:34 -0500 Received: by mail-pl1-f193.google.com with SMTP id g6so645454plp.6 for ; Tue, 11 Feb 2020 23:55:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=VF571MMcb1F1isbPRkdGPyOV5FtumBnPxlJ+7Ql/2kk=; b=M8jzit6j9QXHldQW1vziSBuVrDgF9wRu9w6NmWC+sZyaJWtUZhgeLAMF0x14pFwBw5 5oa/2v1y+DHBalrUVcSKiPaFQ84SEcBZsZTek9oGPffflAIEjDSjPW48ml5l6ZL/YIh4 +EovNwMX9O57bPiJv5hzJijmEHFPoa24QMq0E= 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=VF571MMcb1F1isbPRkdGPyOV5FtumBnPxlJ+7Ql/2kk=; b=dXz49zwuokOAvAMLHokd/dPCKHv0uvlRtSzOe6KwrG1zcCp7LajieeaO3BfmaCLNXf 8ki1YppXwZOnpxqMVYfvgD4MuLSL0YzOsyMLijUu037aknq4T1jxRneQV33jAp1gQoxg fNZFAtwJ1VClDpVEjFsBr35nnGAvY78F0nZHGtgLKd0CN3w0ei9v5zBVoMmHqKAMB82t J1uetXP8dslb/5eumiPe6ATAUtxBm4Gf3zsgSIa4nWNe3qFBhxnJqXL4GnpnWaMT+4zQ HwwNK9CCjxUGol6fBjWUhusqUj4JABO2iqR1z/0mJF3Ij4rk8FYL3P5dwaUTqM3OLxxP ao+A== X-Gm-Message-State: APjAAAViXTnQq1YwFk82VnZByJodEImhtCK3OjcLp0YniBSrZ5v6hO/D KiEzCC6ZvrnBn1zoiQy9CfJiOw== X-Received: by 2002:a17:90a:950b:: with SMTP id t11mr8410462pjo.79.1581494133278; Tue, 11 Feb 2020 23:55:33 -0800 (PST) Received: from drinkcat2.tpe.corp.google.com ([2401:fa00:1:b:d8b7:33af:adcb:b648]) by smtp.gmail.com with ESMTPSA id u126sm7049918pfu.182.2020.02.11.23.55.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2020 23:55:32 -0800 (PST) From: Nicolas Boichat To: Viresh Kumar Cc: Nishanth Menon , Stephen Boyd , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] PM / OPP: Add support for multiple regulators Date: Wed, 12 Feb 2020 15:55:29 +0800 Message-Id: <20200212075529.156756-1-drinkcat@chromium.org> X-Mailer: git-send-email 2.25.0.225.g125e21ebc7-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The OPP table can contain multiple voltages and regulators, and implementing that logic does not add a lot of code or complexity, so let's modify _generic_set_opp_regulator to support that use case. Signed-off-by: Nicolas Boichat --- This is required to add panfrost support for the Bifrost GPU in MT8183, see this patch: https://patchwork.kernel.org/patch/11369821/ drivers/opp/core.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index ba43e6a3dc0aeed..ea4a12a8932014f 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -650,6 +650,24 @@ static int _set_opp_voltage(struct device *dev, struct regulator *reg, return ret; } +/* + * Set multiple voltages. The caller is responsible for restoring all the + * voltages if the function fails. + */ +static int _set_opp_voltages(struct device *dev, struct regulator **regs, + struct dev_pm_opp_supply *supplies, int count) +{ + int i, ret; + + for (i = 0; i < count; i++) { + ret = _set_opp_voltage(dev, regs[i], &supplies[i]); + if (ret) + return ret; + } + + return 0; +} + static inline int _generic_set_opp_clk_only(struct device *dev, struct clk *clk, unsigned long freq) { @@ -671,18 +689,13 @@ static int _generic_set_opp_regulator(const struct opp_table *opp_table, struct dev_pm_opp_supply *old_supply, struct dev_pm_opp_supply *new_supply) { - struct regulator *reg = opp_table->regulators[0]; + struct regulator **regs = opp_table->regulators; + int count = opp_table->regulator_count; int ret; - /* This function only supports single regulator per device */ - if (WARN_ON(opp_table->regulator_count > 1)) { - dev_err(dev, "multiple regulators are not supported\n"); - return -EINVAL; - } - /* Scaling up? Scale voltage before frequency */ if (freq >= old_freq) { - ret = _set_opp_voltage(dev, reg, new_supply); + ret = _set_opp_voltages(dev, regs, new_supply, count); if (ret) goto restore_voltage; } @@ -694,7 +707,7 @@ static int _generic_set_opp_regulator(const struct opp_table *opp_table, /* Scaling down? Scale voltage after frequency */ if (freq < old_freq) { - ret = _set_opp_voltage(dev, reg, new_supply); + ret = _set_opp_voltages(dev, regs, new_supply, count); if (ret) goto restore_freq; } @@ -708,7 +721,7 @@ static int _generic_set_opp_regulator(const struct opp_table *opp_table, restore_voltage: /* This shouldn't harm even if the voltages weren't updated earlier */ if (old_supply) - _set_opp_voltage(dev, reg, old_supply); + _set_opp_voltages(dev, regs, old_supply, count); return ret; } -- 2.25.0.225.g125e21ebc7-goog