From patchwork Fri Oct 12 11:11:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 148748 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp598706lji; Fri, 12 Oct 2018 04:11:47 -0700 (PDT) X-Google-Smtp-Source: ACcGV63ESz+JX2xzMC6UBNnpg2IKoa2hEetkIN5URbbQnBBOmkhnAr5zZ09yqom8AoU47nQodZGZ X-Received: by 2002:a62:e091:: with SMTP id d17-v6mr5565557pfm.214.1539342707486; Fri, 12 Oct 2018 04:11:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539342707; cv=none; d=google.com; s=arc-20160816; b=n7cjKGPjuul3TXAPuPGWBqUzKyEQ6L6L/aavDrqDO0s2t91kmy8a0uZarXiIjtiRwr toHgmnksmVxlMSs52ynjzcdD6+kOLK03+RONYUzPV0HNOsEg2MYfAwuBeg9RhZDrxhyr Aj1eeks/vOEYz/jCJ0QFlmDc2P4MxBNmm3fa7OBxoIQbNud6UbdrPRjasKvU9fN6qb2M bUOTMIUkOLJRFhcxBV6eQddGQ7Ehf8spCTg9/Xr+LKbd4PJixaNqg6yJf00DGb2kAuoL krDcI2sFz5ZeQY9X5UQmPL0DfPYdHjh1/5c38pe7oBuxdIKm44wJ9cQ7ZsJBDsF+SH+C e4CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=6VbMN0cDbtfY/RD+G5z/cfGgvp3V9Mjd6fc+0SIk7q0=; b=y4EdpBPBUV3r1uzEAS/ZErwtCcMwxl6nHvTiLZf9DrLo+GS4it3BecavTJOBFH99nf +cCIJaUPN01styz9ZlXSjYYG6GUS5rdyT4gZ5qlry7ZfdxSQ9bnoLT1qr6HNv7T8wjxQ Bp9P9nbp8F0xV2TOmtXS7VNZ8uoTPvsMEYR1yJU9vsFPKJD+ikJWvv/rqTV+sy/wn96/ KqDhHfUTMKYqQ5M1Yml1/5QWbOZ1MJIaZrH6fGi34PTStTnRnc+zN85EQnqjOV+lErgw t4z6OLI0rW4swFlyu6m7SmumOL1XT1WrVDN7LppaZvchnN4b45T8JKLLzBdYAS1q2ZrB Bl1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b5I2tJ7d; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y76-v6si1006968pfd.254.2018.10.12.04.11.46; Fri, 12 Oct 2018 04:11:47 -0700 (PDT) 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=@linaro.org header.s=google header.b=b5I2tJ7d; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728215AbeJLSnk (ORCPT + 32 others); Fri, 12 Oct 2018 14:43:40 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:41406 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728112AbeJLSnk (ORCPT ); Fri, 12 Oct 2018 14:43:40 -0400 Received: by mail-pg1-f195.google.com with SMTP id 23-v6so5699587pgc.8 for ; Fri, 12 Oct 2018 04:11:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6VbMN0cDbtfY/RD+G5z/cfGgvp3V9Mjd6fc+0SIk7q0=; b=b5I2tJ7dYL9/0L0H4NCF86b+4oh+7rhuCZQsxYhHf5eKcv5WOkx1x9x3Rv0KYV9L+Z RkTM33S6nvAkGdZGrkQWTBcwdootynnw1ZdClJjxguLb90w0I4z5KgY33hQYTGFHKjJk Rs1z+H0rOepvLaCpOOrXRNsjk4QVrrNBxqiY0= 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; bh=6VbMN0cDbtfY/RD+G5z/cfGgvp3V9Mjd6fc+0SIk7q0=; b=maiCEMoMd5tt6w0FP424I3xoGGBnbuXpLLiJS9It8D98gdBtYFGgYwNhyxrgoEbtYz aCTv9Eh3Sx6K1+z1LtI0ROHyCe6Q3hwf2FNrgU6U1AO4mIV3aOXcf2zp58k4oYk+c3RW TC49jyk4yresvai6LM8DU8mA1nam5qWVyUbvX2SCMo8IVuOw+rraSmnk9hH5pRsMH2j8 LIpTBgM7np9MSjjyRu8NCUgz7V16GJjyn9n1qWFKhlCwUnU+3yF6V3sgNfenNPjph67D KrJQ1j8VyWU/5gPovGhUVtaM3ZG0GbQh6VPiGCtxkDBh+p7TX7InWrs5lj6S2cNFTmCs f9Pg== X-Gm-Message-State: ABuFfoj8Sq8k91TdbY8GMiVRogPW+AaxkKBFzq5Idi9SNDo8sEyzohrO 4mT8xI+0x9B/l6Cq9gG6uJVuMA== X-Received: by 2002:a62:d046:: with SMTP id p67-v6mr5811016pfg.147.1539342704246; Fri, 12 Oct 2018 04:11:44 -0700 (PDT) Received: from localhost ([122.171.67.41]) by smtp.gmail.com with ESMTPSA id p1-v6sm3701574pfj.72.2018.10.12.04.11.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 04:11:43 -0700 (PDT) From: Viresh Kumar To: ulf.hansson@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Rafael Wysocki , niklas.cassel@linaro.org, rnayak@codeaurora.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 1/9] OPP: Identify and mark genpd OPP tables Date: Fri, 12 Oct 2018 16:41:09 +0530 Message-Id: <8130f5e3128fbd0dd34b02dbca9cde2b042d2494.1539341929.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We need to handle genpd OPP tables differently, this is already the case at one location and will be extended going forward. Add another field to the OPP table to check if the table belongs to a genpd or not. Signed-off-by: Viresh Kumar --- drivers/opp/of.c | 6 ++++-- drivers/opp/opp.h | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c Reviewed-by: Ulf Hansson diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 5a4b47958073..5f114cd3d88c 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -92,6 +92,9 @@ void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, of_property_read_u32(np, "voltage-tolerance", &opp_table->voltage_tolerance_v1); + if (of_find_property(np, "#power-domain-cells", NULL)) + opp_table->is_genpd = true; + /* Get OPP table node */ opp_np = _opp_of_get_opp_desc_node(np, index); of_node_put(np); @@ -326,8 +329,7 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table, ret = of_property_read_u64(np, "opp-hz", &rate); if (ret < 0) { /* "opp-hz" is optional for devices like power domains. */ - if (!of_find_property(dev->of_node, "#power-domain-cells", - NULL)) { + if (!opp_table->is_genpd) { dev_err(dev, "%s: opp-hz not found\n", __func__); goto free_opp; } diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 9c6544b4f4f9..cdb0c2b095e2 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -140,6 +140,7 @@ enum opp_table_access { * @regulators: Supply regulators * @regulator_count: Number of power supply regulators * @genpd_performance_state: Device's power domain support performance state. + * @is_genpd: Marks if the OPP table belongs to a genpd. * @set_opp: Platform specific set_opp callback * @set_opp_data: Data to be passed to set_opp callback * @dentry: debugfs dentry pointer of the real device directory (not links). @@ -178,6 +179,7 @@ struct opp_table { struct regulator **regulators; unsigned int regulator_count; bool genpd_performance_state; + bool is_genpd; int (*set_opp)(struct dev_pm_set_opp_data *data); struct dev_pm_set_opp_data *set_opp_data; From patchwork Fri Oct 12 11:11:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 148749 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp598779lji; Fri, 12 Oct 2018 04:11:51 -0700 (PDT) X-Google-Smtp-Source: ACcGV6234ZmMqiYuorSHnC5p4artiYMss+Qa/mGLZe55F29hfl5YAJiUvEirmqTRMyidWcTYLZWo X-Received: by 2002:a63:6c84:: with SMTP id h126-v6mr5130452pgc.237.1539342711079; Fri, 12 Oct 2018 04:11:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539342711; cv=none; d=google.com; s=arc-20160816; b=HEbCPYuG69v/rmhx8SJTjAODqcT9hmyJE7TCow+eCB8JPDcNIkOAeKo7TtooiwWTCa Hmt681YiA79Nhm1hlp1cqPGZ+uqWmPR6Q67juuQkJ0TpKyrqoE3PlOUsiEEhUSlRKkos VJfvsjYjcj04KjRN22tmGE60z7QXa8dW8q9h6llcxAg7wLL0Y8I4imAu9RdMXlpDDZ/Z 8SiVQjlSS78sYe3nZLw3QWZJ24AN8JRKtfa/Oz45PaE8NNL9q/IsSe3HKh2j0Z3Ct7aw IXOiN0WhsSdb/+P1H2IwNXo5b6K2I3MOT9e8Lxd33ZqDL6ZZvHVaVabeiNYGyEjdWOjd Gvyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=dZWt165qFows+A3EqmCPCjuilwFrmrgPBXoI72INlkQ=; b=YEqmN4lRHYDHSwbCHT8akkoPWrL9zTp9UJ9Qd2rcjtffFZmTHFN7cV5KW4aOkD8tN1 Iba5UedH/WiVSD/gqnhyFSCeYFXcDe5JBItUuioXHsNqE4XdXCtWBzSy/uLomj24bD/e hHnm6eyySdZgTkTocdpV/YTy2HmNYDASkx3id4mxDgzs4QU5bAVN8MlgRQzemSzfUf/H kGJTaWXGnPsQ3SH5cE1NAK9V9P/A0THqvS5PY79aCKk/6/Aj6BOYXm2wWVFV0eG3xrtr Qdxxs5nxeC3LpAA8s6rMRsDmOgvuuWHhscpWutg+AT4QPq5bYmeHx0lwSSRHvJnIXpWX RTUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jLEMJjEJ; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v2-v6si933143pgc.570.2018.10.12.04.11.50; Fri, 12 Oct 2018 04:11:51 -0700 (PDT) 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=@linaro.org header.s=google header.b=jLEMJjEJ; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728320AbeJLSnn (ORCPT + 32 others); Fri, 12 Oct 2018 14:43:43 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:41514 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728221AbeJLSnn (ORCPT ); Fri, 12 Oct 2018 14:43:43 -0400 Received: by mail-pl1-f193.google.com with SMTP id q17-v6so5787915plr.8 for ; Fri, 12 Oct 2018 04:11:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dZWt165qFows+A3EqmCPCjuilwFrmrgPBXoI72INlkQ=; b=jLEMJjEJtVoUw+m3NYfSuCyvfKiPricSPiHvbQ6DACLinWU3X2w6qfwBEfL6QcFz26 PALTeRPjNUZP3d5/A7t3rA6WkInsG4knVYYiQYM7EoMDcLgHpsDyaA8XHy8pUKpWSIZJ e7SuN/yly+Bmj+rZ6qsQ6A+uvDo/tzofozhHM= 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; bh=dZWt165qFows+A3EqmCPCjuilwFrmrgPBXoI72INlkQ=; b=KCxndOEqqAp/CEn1kxfoEc0YoHVckKNc23xocwzY3VqtiV+wV8vQgldlHu71wFb+mA BHwZUtWJ7zYVP1/z9bSoimH6Sh0QYrhMxh12LhhUKEBA37T8hWUiq4tWJf2WO5zXSeM9 XWdBgoFBXJS42XA6DF5WcS4LnwrgjIBeBTpSWCOsmNk0mwCR3w+Kad9Z+mS1Js+jdZjX eubf/ny9UrX2/57XL0XMDUXuPItG0kysBvZ2oq80D/1B5ZWnq5SIJ5w+qMC2FrUSa9UT uXgToBrPZrN6SvVPC6JA8gVcSdbti2ji90ixZSkbNg15WONOgg6IFD/wAM8iN3DJNQHJ 8/bA== X-Gm-Message-State: ABuFfojL1KtBX3qP7ixbUNdxTCGC9wpyy+HrdFZUVf2htjBUHq32hRK2 lwJ6HfR//Fvyfj6t/6iRUR9log== X-Received: by 2002:a17:902:b182:: with SMTP id s2-v6mr5466352plr.84.1539342707459; Fri, 12 Oct 2018 04:11:47 -0700 (PDT) Received: from localhost ([122.171.67.41]) by smtp.gmail.com with ESMTPSA id c8-v6sm1561084pfi.142.2018.10.12.04.11.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 04:11:46 -0700 (PDT) From: Viresh Kumar To: ulf.hansson@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Rafael Wysocki , niklas.cassel@linaro.org, rnayak@codeaurora.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 2/9] OPP: Separate out custom OPP handler specific code Date: Fri, 12 Oct 2018 16:41:10 +0530 Message-Id: <8e654324f879a04eb0c93493402520f024d2bc17.1539341929.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Create a separate routine to take care of custom set_opp() handler specific stuff. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 67 +++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 27 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c Reviewed-by: Ulf Hansson diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 2c2df4e4fc14..ebb3b648e0fd 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -635,6 +635,34 @@ static int _generic_set_opp_regulator(const struct opp_table *opp_table, return ret; } +static int _set_opp_custom(const struct opp_table *opp_table, + struct device *dev, unsigned long old_freq, + unsigned long freq, + struct dev_pm_opp_supply *old_supply, + struct dev_pm_opp_supply *new_supply) +{ + struct dev_pm_set_opp_data *data; + int size; + + data = opp_table->set_opp_data; + data->regulators = opp_table->regulators; + data->regulator_count = opp_table->regulator_count; + data->clk = opp_table->clk; + data->dev = dev; + + data->old_opp.rate = old_freq; + size = sizeof(*old_supply) * opp_table->regulator_count; + if (IS_ERR(old_supply)) + memset(data->old_opp.supplies, 0, size); + else + memcpy(data->old_opp.supplies, old_supply, size); + + data->new_opp.rate = freq; + memcpy(data->new_opp.supplies, new_supply, size); + + return opp_table->set_opp(data); +} + /** * dev_pm_opp_set_rate() - Configure new OPP based on frequency * @dev: device for which we do this operation @@ -649,7 +677,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) unsigned long freq, old_freq; struct dev_pm_opp *old_opp, *opp; struct clk *clk; - int ret, size; + int ret; if (unlikely(!target_freq)) { dev_err(dev, "%s: Invalid target frequency %lu\n", __func__, @@ -702,8 +730,17 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) dev_dbg(dev, "%s: switching OPP: %lu Hz --> %lu Hz\n", __func__, old_freq, freq); - /* Only frequency scaling */ - if (!opp_table->regulators) { + if (opp_table->set_opp) { + ret = _set_opp_custom(opp_table, dev, old_freq, freq, + IS_ERR(old_opp) ? NULL : old_opp->supplies, + opp->supplies); + } else if (opp_table->regulators) { + ret = _generic_set_opp_regulator(opp_table, dev, old_freq, freq, + IS_ERR(old_opp) ? NULL : old_opp->supplies, + opp->supplies); + } else { + /* Only frequency scaling */ + /* * We don't support devices with both regulator and * domain performance-state for now. @@ -714,30 +751,6 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) opp->pstate); else ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq); - } else if (!opp_table->set_opp) { - ret = _generic_set_opp_regulator(opp_table, dev, old_freq, freq, - IS_ERR(old_opp) ? NULL : old_opp->supplies, - opp->supplies); - } else { - struct dev_pm_set_opp_data *data; - - data = opp_table->set_opp_data; - data->regulators = opp_table->regulators; - data->regulator_count = opp_table->regulator_count; - data->clk = clk; - data->dev = dev; - - data->old_opp.rate = old_freq; - size = sizeof(*opp->supplies) * opp_table->regulator_count; - if (IS_ERR(old_opp)) - memset(data->old_opp.supplies, 0, size); - else - memcpy(data->old_opp.supplies, old_opp->supplies, size); - - data->new_opp.rate = freq; - memcpy(data->new_opp.supplies, opp->supplies, size); - - ret = opp_table->set_opp(data); } dev_pm_opp_put(opp); From patchwork Fri Oct 12 11:11:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 148750 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp598856lji; Fri, 12 Oct 2018 04:11:54 -0700 (PDT) X-Google-Smtp-Source: ACcGV61HevwWZwSeHCYmFz6QqBFIfh7aD+N/woI5rHURVFCmrwUN0nsh++4yR5IxTWUMOdt6/YIP X-Received: by 2002:a17:902:28a2:: with SMTP id f31-v6mr5540872plb.312.1539342714581; Fri, 12 Oct 2018 04:11:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539342714; cv=none; d=google.com; s=arc-20160816; b=yHc3trZrEh3izA7DUckQ/KhSBAvUUusiGLjQeVl/g4dXPDDBGMWVv6UDJDxrrSCTKd p9Wc1umtR6K+PaeNTybNDK+4YpdC/TItHP1rYxaAAf/or3cItdY4G8ol/fZ3XrGkB2vJ FsjkgUDX2gVefX5Z8AMG/UZhwXFrX53UW0G9dAJ+Ch3lhEw3KCyqrU6IE1CnswrHqeFw J56u0VtjJJDa7+8sge1SsqpgTX/hEIt7pR0ihnmwWm6kBk9g6FXYxA3qcZP0cwLbRTSj sKuNew8aGSQndFxnC91Y8a52WLcRZAK0TEvotaZBKP8IZb4DrXmbr9eNWe4yH+zMemZK HnRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=uorCkJdWaF4Sj11ejs2yohL+5s4N2Cuzv1QinYIziLw=; b=zlZXZogvy/UPgGwxy0Os2BPD3tDmciP3ZX6I0aAPd6/C8vUygDnt6Mhnfm58KRHrfx nrnKQXmsEmwymcdu2/+3BSPJ9sZRgjqqRJT0Rwh+jcxiuvds5nxhxGkhGnIfWRt36a2f jN0eXZmC8jp7UTM1xSPC1bwb2Ev5Dn60K/nwp/xRua7g/VKi8qy4cUYU6Imkr2akP2zH El9p9opCqHzXkosvQQmMOIq9IXErpO0nnXx9v04GMV+WBxEC2f2TZ9JgKFpVBDYO2kn9 Y7GPujJvcYzLd2l70ZM0630WiyI4xdvxwk2yXHQ+7e5o5IZ9q8R4wVdalJ0OTf2RTfA/ /FaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d+YhLrgu; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a3-v6si940304plp.199.2018.10.12.04.11.54; Fri, 12 Oct 2018 04:11:54 -0700 (PDT) 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=@linaro.org header.s=google header.b=d+YhLrgu; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728360AbeJLSnr (ORCPT + 32 others); Fri, 12 Oct 2018 14:43:47 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:42242 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728221AbeJLSnr (ORCPT ); Fri, 12 Oct 2018 14:43:47 -0400 Received: by mail-pf1-f193.google.com with SMTP id f26-v6so6024798pfn.9 for ; Fri, 12 Oct 2018 04:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uorCkJdWaF4Sj11ejs2yohL+5s4N2Cuzv1QinYIziLw=; b=d+YhLrgumT70qMbcIzEornH5OlOpNrddfnFUOQwfF72Fpmc7Ll04Wyak68dKJCJXxE WwS5su3vpDr0hVL0F0osGSM+XFXSzO76JysChJONpp08OrwgjSqa/IPwlP7WHjdqVTPS MP5kAd7zeBxnVHaeIyfHoQj372pXosErKiaNk= 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; bh=uorCkJdWaF4Sj11ejs2yohL+5s4N2Cuzv1QinYIziLw=; b=kn16fjdBPOpfaT3aAUGz7E686tqXHnw7cpZ2VUOb4VKUXMpWmTneh0YXPYaQq7NbdN A4M/2CwlnCa+sCXwyi7WtHSz8q5R/um+T9lplSZT71eajiNdUwNiEbwANwMVT2e0KoTJ LTS0neNTbtISf5dwaaJKtaMtv7hu6deblr9WQwiAf+MZeueH3aQLC/x6bbsaO8GhJIWu B6QPBOJmWsadsSNYWgYP2eMK1a8ifgCllIHjqSDmW6JmujZbmMeThVil8iplNBzwxIAw aieOHD+PKCk0H0JgdJGtBY09w+kEbkmvGk09ib7fZvMqLOVSg8seBapSLJSBgsP9uMYx QAXA== X-Gm-Message-State: ABuFfojfMGDfVv/5Q2DtP3R+ByEVlVl9D56TcUUMegQaowoOx2yij+RD yRHOszPVHtG7DV8O9Q9h+BafVw== X-Received: by 2002:a63:608c:: with SMTP id u134-v6mr5028829pgb.266.1539342711020; Fri, 12 Oct 2018 04:11:51 -0700 (PDT) Received: from localhost ([122.171.67.41]) by smtp.gmail.com with ESMTPSA id y19-v6sm2510927pff.14.2018.10.12.04.11.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 04:11:50 -0700 (PDT) From: Viresh Kumar To: ulf.hansson@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Rafael Wysocki , niklas.cassel@linaro.org, rnayak@codeaurora.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 3/9] OPP: Populate required opp tables from "required-opps" property Date: Fri, 12 Oct 2018 16:41:11 +0530 Message-Id: <55853fb39ed5c7c01ec8dfb78f53a32b5dc98966.1539341929.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current implementation works only for the case where a single phandle is present in the "required-opps" property, while DT allows multiple phandles to be present there. This patch adds new infrastructure to parse all the phandles present in "required-opps" property and save pointers of the required OPP's OPP tables. These will be used by later commits. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 2 + drivers/opp/of.c | 147 +++++++++++++++++++++++++++++++++++++++++++++ drivers/opp/opp.h | 8 +++ 3 files changed, 157 insertions(+) -- 2.18.0.rc1.242.g61856ae69a2c diff --git a/drivers/opp/core.c b/drivers/opp/core.c index ebb3b648e0fd..85174a5c4850 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -901,6 +901,8 @@ static void _opp_table_kref_release(struct kref *kref) struct opp_table *opp_table = container_of(kref, struct opp_table, kref); struct opp_device *opp_dev, *temp; + _of_clear_opp_table(opp_table); + /* Release clk */ if (!IS_ERR(opp_table->clk)) clk_put(opp_table->clk); diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 5f114cd3d88c..b5605196122a 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -73,6 +73,147 @@ struct opp_table *_managed_opp(struct device *dev, int index) return managed_table; } +/* The caller must call dev_pm_opp_put() after the OPP is used */ +static struct dev_pm_opp *_find_opp_of_np(struct opp_table *opp_table, + struct device_node *opp_np) +{ + struct dev_pm_opp *opp; + + lockdep_assert_held(&opp_table_lock); + + mutex_lock(&opp_table->lock); + + list_for_each_entry(opp, &opp_table->opp_list, node) { + if (opp->np == opp_np) { + dev_pm_opp_get(opp); + mutex_unlock(&opp_table->lock); + return opp; + } + } + + mutex_unlock(&opp_table->lock); + + return NULL; +} + +static struct device_node *of_parse_required_opp(struct device_node *np, + int index) +{ + struct device_node *required_np; + + required_np = of_parse_phandle(np, "required-opps", index); + if (unlikely(!required_np)) { + pr_err("%s: Unable to parse required-opps: %pOF, index: %d\n", + __func__, np, index); + } + + return required_np; +} + +/* The caller must call dev_pm_opp_put_opp_table() after the table is used */ +static struct opp_table *_find_table_of_opp_np(struct device_node *opp_np) +{ + struct opp_table *opp_table; + struct dev_pm_opp *opp; + + lockdep_assert_held(&opp_table_lock); + + list_for_each_entry(opp_table, &opp_tables, node) { + opp = _find_opp_of_np(opp_table, opp_np); + if (opp) { + dev_pm_opp_put(opp); + _get_opp_table_kref(opp_table); + return opp_table; + } + } + + return ERR_PTR(-ENODEV); +} + +/* Free resources previously acquired by _opp_table_alloc_required_tables() */ +static void _opp_table_free_required_tables(struct opp_table *opp_table) +{ + struct opp_table **required_opp_tables = opp_table->required_opp_tables; + int i; + + if (!required_opp_tables) + return; + + for (i = 0; i < opp_table->required_opp_count; i++) { + if (IS_ERR_OR_NULL(required_opp_tables[i])) + break; + + dev_pm_opp_put_opp_table(required_opp_tables[i]); + } + + kfree(required_opp_tables); + + opp_table->required_opp_count = 0; + opp_table->required_opp_tables = NULL; +} + +/* + * Populate all devices and opp tables which are part of "required-opps" list. + * Checking only the first OPP node should be enough. + */ +static void _opp_table_alloc_required_tables(struct opp_table *opp_table, + struct device *dev, + struct device_node *opp_np) +{ + struct opp_table **required_opp_tables; + struct device_node *required_np, *np; + int count, i; + + /* Traversing the first OPP node is all we need */ + np = of_get_next_available_child(opp_np, NULL); + if (!np) { + dev_err(dev, "Empty OPP table\n"); + return; + } + + count = of_count_phandle_with_args(np, "required-opps", NULL); + if (!count) + goto put_np; + + required_opp_tables = kcalloc(count, sizeof(*required_opp_tables), + GFP_KERNEL); + if (!required_opp_tables) + goto put_np; + + opp_table->required_opp_tables = required_opp_tables; + opp_table->required_opp_count = count; + + for (i = 0; i < count; i++) { + required_np = of_parse_required_opp(np, i); + if (!required_np) + goto free_required_tables; + + required_opp_tables[i] = _find_table_of_opp_np(required_np); + of_node_put(required_np); + + if (IS_ERR(required_opp_tables[i])) + goto free_required_tables; + + /* + * We only support genpd's OPPs in the "required-opps" for now, + * as we don't know how much about other cases. Error out if the + * required OPP doesn't belong to a genpd. + */ + if (!required_opp_tables[i]->is_genpd) { + dev_err(dev, "required-opp doesn't belong to genpd: %pOF\n", + required_np); + goto free_required_tables; + } + } + + goto put_np; + +free_required_tables: + _opp_table_free_required_tables(opp_table); +put_np: + of_node_put(np); +} + void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index) { @@ -109,9 +250,15 @@ void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, opp_table->np = opp_np; + _opp_table_alloc_required_tables(opp_table, dev, opp_np); of_node_put(opp_np); } +void _of_clear_opp_table(struct opp_table *opp_table) +{ + _opp_table_free_required_tables(opp_table); +} + static bool _opp_is_supported(struct device *dev, struct opp_table *opp_table, struct device_node *np) { diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index cdb0c2b095e2..024e1be23d37 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -133,6 +133,9 @@ enum opp_table_access { * @parsed_static_opps: True if OPPs are initialized from DT. * @shared_opp: OPP is shared between multiple devices. * @suspend_opp: Pointer to OPP to be used during device suspend. + * @required_opp_tables: List of device OPP tables that are required by OPPs in + * this table. + * @required_opp_count: Number of required devices. * @supported_hw: Array of version number to support. * @supported_hw_count: Number of elements in supported_hw array. * @prop_name: A name to postfix to many DT properties, while parsing them. @@ -172,6 +175,9 @@ struct opp_table { enum opp_table_access shared_opp; struct dev_pm_opp *suspend_opp; + struct opp_table **required_opp_tables; + unsigned int required_opp_count; + unsigned int *supported_hw; unsigned int supported_hw_count; const char *prop_name; @@ -208,9 +214,11 @@ void _put_opp_list_kref(struct opp_table *opp_table); #ifdef CONFIG_OF void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index); +void _of_clear_opp_table(struct opp_table *opp_table); struct opp_table *_managed_opp(struct device *dev, int index); #else static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index) {} +static inline void _of_clear_opp_table(struct opp_table *opp_table) {} static inline struct opp_table *_managed_opp(struct device *dev, int index) { return NULL; } #endif From patchwork Fri Oct 12 11:11:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 148751 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp598966lji; Fri, 12 Oct 2018 04:12:00 -0700 (PDT) X-Google-Smtp-Source: ACcGV60/yzLhbaozykczn1ejfU8CO/vNk44caDaH6AItQeKIZd8BhnU09bXsqcZ64DjcRPuCMqBZ X-Received: by 2002:a17:902:263:: with SMTP id 90-v6mr5476021plc.190.1539342720012; Fri, 12 Oct 2018 04:12:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539342720; cv=none; d=google.com; s=arc-20160816; b=Cu9ske7LFSnf6CvQfYnsN9f95VBBVbfZhHTVXJN8zik4MXyhsd6dYWJA7WnxvFFcgG fmc1JTWcCgv1rlUYhgWUmsO0YfzVY2nhGctOSnw4fB9SW4++IL8poUeIrr7BnOdWtwHw Fy55q2NfK9XEtZpJeaKOvcBTvAhQF9HF2+Z0JHt5n9gm91RdaD7rglCxZRz75EfCmK98 UVNnDjISqZW+A7TKPKt97x8ccptNypk64QvOl3z5XoOxqqf4rE4MuLYOsHAOg/sqRQwT UBMcPsbjArQj4HeOfqZPn6XCaQ7jWxyAAJbQWgjlpOkD7Q9GqIAJ3vFYoa3uxfDKu7gn UPlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=DQoC/dGulf7GeSU4tYiMeHj0m5zjqTSJW02yJ/gDIGc=; b=EnLszTEXUWKIE95EC5WDL23VLY+SxbwcDAh6zEY9v0zDs0QCxlbmrrXwGUPu0nUNoe uoeON8DLRDzatI4fFv4oUMqLlpegn9noh0mFjTPVB7iQKTeOq+MHywU67hal72rQj+yK /9Q2rpGbqGamZE6nXqp+UIoSPvQQ2F7eNTPwc92exRgRh+NtTbODLxN/mGOp/YgznL47 G9L1fHkjpu82VSTGYpy1EYDJljn8DGdVF0ws8ACArKcgWTpypvVCFmuHlmbiqKgkqq9N sNF2nxvXy8oaI0mg6AEacUGIR91kthk575uSGng5qhtgVhYkwAdbQDRI5J1HN7+Q7avN CIPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VPGChhOU; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e92-v6si995780pld.358.2018.10.12.04.11.58; Fri, 12 Oct 2018 04:11:59 -0700 (PDT) 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=@linaro.org header.s=google header.b=VPGChhOU; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728433AbeJLSnv (ORCPT + 32 others); Fri, 12 Oct 2018 14:43:51 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:38407 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728368AbeJLSnu (ORCPT ); Fri, 12 Oct 2018 14:43:50 -0400 Received: by mail-pl1-f194.google.com with SMTP id q19-v6so2707463pll.5 for ; Fri, 12 Oct 2018 04:11:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DQoC/dGulf7GeSU4tYiMeHj0m5zjqTSJW02yJ/gDIGc=; b=VPGChhOU/EqM6/yck0FUGBiRf8kidRyRqg6f0gzXWR+IxmnZ/Ut+uUg3Rf+MGaIu5T JN5NwQH/9MhZj162Inqwcpt7M3ZL55+JHl5wvDcpGfdLF4BEf7eFjZV1LFAqwd1eCoGe mJNManKmK6IqGy4MQzm7XD7caUj7zR1N6fjGs= 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; bh=DQoC/dGulf7GeSU4tYiMeHj0m5zjqTSJW02yJ/gDIGc=; b=hEux9d4vEhw1uc/9yLkg85Xjtg2P8cPoTbmy+x9Gh1pPVSBJAF2+UXnmlNq2FTJBhW M1hL6pUz8nUeQiCBm/ofJbFf6wyjKYEFx7FGvHy4/+41vxOERDSSl3XLewTjTPtEgyGZ qm43ETh3W8P9EOpsa6Ezk6wawMvuLYat8dbkU0hv71q4UoP6MJ5BUpPgrouce3XSaVRF 9pKC4e00kXz+vLjWzKrT16q+QXt5fCw6xwgQBJPLLyoDzOm1pMSJqjb2nCmf49UNhido vD/x7GtsBNkRQiif29j75iLLErnYQug8oEIRNBSMllL87vji53Mjk+aedJPIBlQB7Ll9 O4NA== X-Gm-Message-State: ABuFfog/StZt9D7V+wDpE5MDudwolPdWg0Gm4e1m0tHq5oP8FExOuIPv bkE9/2Ym+31oHmfHFwqfDwWY0w== X-Received: by 2002:a17:902:850b:: with SMTP id bj11-v6mr5594013plb.107.1539342714321; Fri, 12 Oct 2018 04:11:54 -0700 (PDT) Received: from localhost ([122.171.67.41]) by smtp.gmail.com with ESMTPSA id m10-v6sm1293959pgp.94.2018.10.12.04.11.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 04:11:53 -0700 (PDT) From: Viresh Kumar To: ulf.hansson@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Rafael Wysocki , niklas.cassel@linaro.org, rnayak@codeaurora.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 4/9] OPP: Populate OPPs from "required-opps" property Date: Fri, 12 Oct 2018 16:41:12 +0530 Message-Id: <16fe09d146a2bcd892a62fec595252b1cb2e539d.1539341929.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org An earlier commit populated the OPP tables from the "required-opps" property, this commit populates the individual OPPs. This is repeated for each OPP in the OPP table and these populated OPPs will be used by later commits. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 1 + drivers/opp/of.c | 81 ++++++++++++++++++++++++++++++++++++++++++++-- drivers/opp/opp.h | 6 ++++ 3 files changed, 86 insertions(+), 2 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c Reviewed-by: Ulf Hansson diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 85174a5c4850..02a69a62dac8 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -976,6 +976,7 @@ static void _opp_kref_release(struct kref *kref) * frequency/voltage list. */ blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_REMOVE, opp); + _of_opp_free_required_opps(opp_table, opp); opp_debug_remove_one(opp); list_del(&opp->node); kfree(opp); diff --git a/drivers/opp/of.c b/drivers/opp/of.c index b5605196122a..ffaeefef98ce 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -259,6 +259,77 @@ void _of_clear_opp_table(struct opp_table *opp_table) _opp_table_free_required_tables(opp_table); } +/* + * Release all resources previously acquired with a call to + * _of_opp_alloc_required_opps(). + */ +void _of_opp_free_required_opps(struct opp_table *opp_table, + struct dev_pm_opp *opp) +{ + struct dev_pm_opp **required_opps = opp->required_opps; + int i; + + if (!required_opps) + return; + + for (i = 0; i < opp_table->required_opp_count; i++) { + if (!required_opps[i]) + break; + + /* Put the reference back */ + dev_pm_opp_put(required_opps[i]); + } + + kfree(required_opps); + opp->required_opps = NULL; +} + +/* Populate all required OPPs which are part of "required-opps" list */ +static int _of_opp_alloc_required_opps(struct opp_table *opp_table, + struct dev_pm_opp *opp) +{ + struct dev_pm_opp **required_opps; + struct opp_table *required_table; + struct device_node *np; + int i, ret, count = opp_table->required_opp_count; + + if (!count) + return 0; + + required_opps = kcalloc(count, sizeof(*required_opps), GFP_KERNEL); + if (!required_opps) + return -ENOMEM; + + opp->required_opps = required_opps; + + for (i = 0; i < count; i++) { + required_table = opp_table->required_opp_tables[i]; + + np = of_parse_required_opp(opp->np, i); + if (unlikely(!np)) { + ret = -ENODEV; + goto free_required_opps; + } + + required_opps[i] = _find_opp_of_np(required_table, np); + of_node_put(np); + + if (!required_opps[i]) { + pr_err("%s: Unable to find required OPP node: %pOF (%d)\n", + __func__, opp->np, i); + ret = -ENODEV; + goto free_required_opps; + } + } + + return 0; + +free_required_opps: + _of_opp_free_required_opps(opp_table, opp); + + return ret; +} + static bool _opp_is_supported(struct device *dev, struct opp_table *opp_table, struct device_node *np) { @@ -503,6 +574,10 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table, new_opp->dynamic = false; new_opp->available = true; + ret = _of_opp_alloc_required_opps(opp_table, new_opp); + if (ret) + goto free_opp; + if (!of_property_read_u32(np, "clock-latency-ns", &val)) new_opp->clock_latency_ns = val; @@ -510,14 +585,14 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table, ret = opp_parse_supplies(new_opp, dev, opp_table); if (ret) - goto free_opp; + goto free_required_opps; ret = _opp_add(dev, new_opp, opp_table, rate_not_available); if (ret) { /* Don't return error for duplicate OPPs */ if (ret == -EBUSY) ret = 0; - goto free_opp; + goto free_required_opps; } /* OPP to select on device suspend */ @@ -547,6 +622,8 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table, blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADD, new_opp); return new_opp; +free_required_opps: + _of_opp_free_required_opps(opp_table, new_opp); free_opp: _opp_free(new_opp); diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 024e1be23d37..24b340ad18d1 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -63,6 +63,7 @@ extern struct list_head opp_tables; * @supplies: Power supplies voltage/current values * @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's * frequency from any other OPP's frequency. + * @required_opps: List of OPPs that are required by this OPP. * @opp_table: points back to the opp_table struct this opp belongs to * @np: OPP's device node. * @dentry: debugfs dentry pointer (per opp) @@ -84,6 +85,7 @@ struct dev_pm_opp { unsigned long clock_latency_ns; + struct dev_pm_opp **required_opps; struct opp_table *opp_table; struct device_node *np; @@ -216,10 +218,14 @@ void _put_opp_list_kref(struct opp_table *opp_table); void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index); void _of_clear_opp_table(struct opp_table *opp_table); struct opp_table *_managed_opp(struct device *dev, int index); +void _of_opp_free_required_opps(struct opp_table *opp_table, + struct dev_pm_opp *opp); #else static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index) {} static inline void _of_clear_opp_table(struct opp_table *opp_table) {} static inline struct opp_table *_managed_opp(struct device *dev, int index) { return NULL; } +static inline void _of_opp_free_required_opps(struct opp_table *opp_table, + struct dev_pm_opp *opp) {} #endif #ifdef CONFIG_DEBUG_FS From patchwork Fri Oct 12 11:11:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 148752 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp599009lji; Fri, 12 Oct 2018 04:12:02 -0700 (PDT) X-Google-Smtp-Source: ACcGV63nXqbEvHKhMEC/xDPQna2gPsP8+Y6uk4xsJbMmgPASWWWSN4a17DkguNhxLp6WSd0MwnSA X-Received: by 2002:a63:cc:: with SMTP id 195-v6mr5060877pga.44.1539342722598; Fri, 12 Oct 2018 04:12:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539342722; cv=none; d=google.com; s=arc-20160816; b=f/GE4oc3oDcbdsKXpAUbpSdiJ/pfsKweyQfo+DpA5ul0Gor96rmmESH3R9d0triHjr s/fbKyxdjlrPXP16WkytvSYZsPjaVnP0FMIEHZG+N85jiuo83jq/0q2/n6jCT1+gZeB3 GeCuLiGUBTfOHUMt5Oo4PSTJohzFPz8gx4UTz9awv810hG24UFzjovCOqizg5VQgz44E AWEJ+dSPHfG2D8XlXKUZWJ7xjtA6HlP3kaFJoTXx4rGFB6f77ztyouIJJFfcFm9pHcsn /SXgtj9R/UBDZ0IngLDfsVR9a1ZwMhm2RLp10eCiT2BChArQe0xhqttoxsZQvGygQfpG jkww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=blaWPqPFlJGJ+DD2m7muSQ78d8p4LHOlTL3txRfKTuM=; b=pmU1aGzCyPX568Xxykb64d2YdUmd/evGAOqiHEkXlyeIdKckPwxSAFII46UT2xcnKP TOGI7+i83HosyAADAfEE/iW1TTGrMdWYNzjkRi74k/gfuCPJ0rQ9hgeApKPcNdhgUPT7 ByRjfEeFuTCzlybSwyULZkDG6THSIKDh75C45j+Q7IByXQA63O6q3CYrlAwF1DZn8ak6 KpzpGTbKIBy3P6q02OjBq0j+cFs6ZVyt7yHL8MN+G2y3qNOo7fZaniUbkhkmm1vTDMom 2iGsfjs/KnRkMMvsVMnyyXKGN6serdWthbig2LwWQUSYGh3IbUCxzPtE1DvQX5vxTkO/ XNPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D5rUBQr1; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11-v6si1072844pgr.65.2018.10.12.04.12.01; Fri, 12 Oct 2018 04:12:02 -0700 (PDT) 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=@linaro.org header.s=google header.b=D5rUBQr1; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728464AbeJLSnz (ORCPT + 32 others); Fri, 12 Oct 2018 14:43:55 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:45047 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728368AbeJLSnx (ORCPT ); Fri, 12 Oct 2018 14:43:53 -0400 Received: by mail-pl1-f193.google.com with SMTP id p25-v6so5778651pli.11 for ; Fri, 12 Oct 2018 04:11:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=blaWPqPFlJGJ+DD2m7muSQ78d8p4LHOlTL3txRfKTuM=; b=D5rUBQr1vrcVc2BiXCmd7EiQMTO1uXdbtMYnWRamB5cquWHi9NzLxeEsCMD0M9wOgo PHNKNZrl2nVXuRuwsowZrfnIswszWdoTKiBxdadMSfSDWAEwRn7SPyGBVf8ezP66W1TL GtoFhOj9S7JgD8sZTolBIrQkHyr3Xfi0uqygY= 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; bh=blaWPqPFlJGJ+DD2m7muSQ78d8p4LHOlTL3txRfKTuM=; b=sWKHsjxkk74jNippRcwoHC/k09fmyUB3rIwSW1cXSZhAY3GK3qLaUo24GizmqLSH0p ZsYFbWJawI/XliPvbcB0DD3SC6Iffpnb7zaoSkxBUWbJAIwMzN+gAbXHCqqWgU0T+NPa L6LQm84/TO+PSzT9YijgV9pN86bCFMnaroVLmEkrw29cTF7Vnu6neNrClz0vD2tUZXJN DlUDHxJFOj1rBr3itq0tNO+3v3AcRniEFe7W0M2c4TdFs/XEzju/daw5lU60LVAaFRYP BIeuj2eSqDn96JrJzW0m7gQGIV0GKoT15LQmeSoyku9jX4FiCSQGO7nhezbk9V9Km0Vg +51w== X-Gm-Message-State: ABuFfogPFe04KhMd5u6UzgQP5dd30xznIelCmaMeIUFGXd1CvOayShe2 NEAhosiW35t+1pJcVgiqFbb0Rg== X-Received: by 2002:a17:902:1129:: with SMTP id d38-v6mr156721pla.270.1539342717651; Fri, 12 Oct 2018 04:11:57 -0700 (PDT) Received: from localhost ([122.171.67.41]) by smtp.gmail.com with ESMTPSA id l129-v6sm2092376pfc.155.2018.10.12.04.11.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 04:11:57 -0700 (PDT) From: Viresh Kumar To: ulf.hansson@linaro.org, "Rafael J. Wysocki" , Kevin Hilman , Pavel Machek , Len Brown Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Stephen Boyd , Nishanth Menon , niklas.cassel@linaro.org, rnayak@codeaurora.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 5/9] PM / Domains: Add genpd_opp_to_performance_state() Date: Fri, 12 Oct 2018 16:41:13 +0530 Message-Id: X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The OPP core currently stores the performance state in the consumer device's OPP table, but that is going to change going forward and performance state will rather be set directly in the genpd's OPP table. For that we need to get the performance state for genpd's device structure instead of the consumer device's structure. Add a new helper to do that. Signed-off-by: Viresh Kumar --- drivers/base/power/domain.c | 39 +++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 8 ++++++++ 2 files changed, 47 insertions(+) -- 2.18.0.rc1.242.g61856ae69a2c diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 4b5714199490..2c82194d2a30 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2508,6 +2508,45 @@ int of_genpd_parse_idle_states(struct device_node *dn, } EXPORT_SYMBOL_GPL(of_genpd_parse_idle_states); +/** + * genpd_opp_to_performance_state- Gets performance state of the genpd from its OPP node. + * + * @genpd_dev: Genpd's device for which the performance-state needs to be found. + * @opp: struct dev_pm_opp of the OPP for which we need to find performance + * state. + * + * Returns performance state encoded in the OPP of the genpd. This calls + * platform specific genpd->opp_to_performance_state() callback to translate + * power domain OPP to performance state. + * + * Returns performance state on success and 0 on failure. + */ +unsigned int genpd_opp_to_performance_state(struct device *genpd_dev, + struct dev_pm_opp *opp) +{ + struct generic_pm_domain *genpd = NULL, *temp; + int state; + + lockdep_assert_held(&gpd_list_lock); + + list_for_each_entry(temp, &gpd_list, gpd_list_node) { + if (&temp->dev == genpd_dev) { + genpd = temp; + break; + } + } + + if (unlikely(!genpd || !genpd->opp_to_performance_state)) + return 0; + + genpd_lock(genpd); + state = genpd->opp_to_performance_state(genpd, opp); + genpd_unlock(genpd); + + return state; +} +EXPORT_SYMBOL_GPL(genpd_opp_to_performance_state); + /** * of_genpd_opp_to_performance_state- Gets performance state of device's * power domain corresponding to a DT node's "required-opps" property. diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 776c546d581a..e03f300f7468 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -233,6 +233,8 @@ int of_genpd_add_subdomain(struct of_phandle_args *parent, struct generic_pm_domain *of_genpd_remove_last(struct device_node *np); int of_genpd_parse_idle_states(struct device_node *dn, struct genpd_power_state **states, int *n); +unsigned int genpd_opp_to_performance_state(struct device *genpd_dev, + struct dev_pm_opp *opp); unsigned int of_genpd_opp_to_performance_state(struct device *dev, struct device_node *np); @@ -274,6 +276,12 @@ static inline int of_genpd_parse_idle_states(struct device_node *dn, return -ENODEV; } +static inline unsigned int +genpd_opp_to_performance_state(struct device *genpd_dev, struct dev_pm_opp *opp) +{ + return 0; +} + static inline unsigned int of_genpd_opp_to_performance_state(struct device *dev, struct device_node *np) From patchwork Fri Oct 12 11:11:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 148753 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp599084lji; Fri, 12 Oct 2018 04:12:06 -0700 (PDT) X-Google-Smtp-Source: ACcGV610ZUC+sGpPiDv1WDjBxKk5/c+5dyT9h3Jsi0IIsEt9obaEFHCrFMX73ajitCKBCuFnVzgO X-Received: by 2002:aa7:8598:: with SMTP id w24-v6mr5732463pfn.77.1539342726580; Fri, 12 Oct 2018 04:12:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539342726; cv=none; d=google.com; s=arc-20160816; b=grryxcXSK759taa+GGTCMI5RGC70XF5E2RF63W/C2s7/eNIsSrVieLEtYMMMwA+wS9 0bu0Yp13m4UyoWTuAyLtYd5EsztjO45tTB4yO5Q/w4hUV3VMn83bT/dxgAIzVLJBDblN 2xtv5Mnqp0tISvYKGEYHR1PtIj7bOhZBCP3ZTlVtPn8yAnetS83vv3qgcA846ifpFUpt +V0qxhZsB9nHrwZic5IB6xij/l+evWMTPfMXJl2LZAMGMI22etfi9J1tGQti1zIQT6Kz Hmfj7rR8I45KuQErWnKJ46h/qs0Z7iGP3frgGzA291JaX8UIkUKvPxLdA9OmS4/6q+is k5aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=Tq2uoD3eSZPlHD8aKVhELPwsZk/flECXrnGOvj2sO+4=; b=aNe0CpDHqJKXSI8hkHrXmJuwNbzc7M9Q9jzv4EU1nwTCoCPtZ+Ynx3ey2jKbFgMPK8 KXdUZA92VQPBQUQ7U/uj1D7Zgw2Q/G1Xul6xcjp25sEEnsKQcppTlmibaXFQyX3wI2zj PrZnDQ/Pfh1DsEnU9J/5ZD6yW2/8aG6hwwcI3rzCw246yBMP0zZoChr3tz1/PmjA2i7M lenevYZjsJGekGd+abDZLUz49RYUPUloJZva8rHKxPlByVH0BCmIXvEhbuvUPztH7LnV fk5HBIT8uBXgx/xC+JYbJf1GSt8Df9x4Woyrem7Z0y6VCafeqiC4HPmKnhFajA2c6dwg NJyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dhkFqvWW; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r198-v6si970181pgr.456.2018.10.12.04.12.05; Fri, 12 Oct 2018 04:12:06 -0700 (PDT) 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=@linaro.org header.s=google header.b=dhkFqvWW; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728521AbeJLSn7 (ORCPT + 32 others); Fri, 12 Oct 2018 14:43:59 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:40813 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728489AbeJLSn6 (ORCPT ); Fri, 12 Oct 2018 14:43:58 -0400 Received: by mail-pf1-f195.google.com with SMTP id s5-v6so6036191pfj.7 for ; Fri, 12 Oct 2018 04:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Tq2uoD3eSZPlHD8aKVhELPwsZk/flECXrnGOvj2sO+4=; b=dhkFqvWW+IcaZhMuIMWGePI24oiriSJpj8hf88QLRQhGgSCpE4lkgjex/jBZcBtStb K3BMrUCZ6lCJaDOW1tPKR1ag5NYyltBtBQ5wRHQUDscshUWSAFR6zzSj4HbnLD/rV9nF oxM29V07NM7soh+riIMnv1VUoQ8lGkTIj2fC4= 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; bh=Tq2uoD3eSZPlHD8aKVhELPwsZk/flECXrnGOvj2sO+4=; b=OsoDlLcU+rSHTtcI/5BPPqUp0acul1d4Kxf8ycBtIpeY/Fyzi5BI6CUl0r57A77Nh8 W371iIqJVWLa1r4jqmliUZyFUZbpaJu1TaXrtxcMEV7CU5nl04FpHkNRjB9nbzIey/K+ huhjcC/e925zb8//ziIWPuVYden0VV8hgz2Vlls7/mlXs5L3R/0xGDclX+JRk54PPv3D lctOm8aZrnTXFIzucOYhyEqXYR/PpZ8rdziIPuCz4t2tn7tkxRmOnTWpvMWE7Qgfbpd5 jzW8VLihbBI2Kkb9Ele3spCFROEHQp00XHxV3+pBmAFbP0Clm3mqkppVHavV9Po1R7pa Pyuw== X-Gm-Message-State: ABuFfoikKwowEO8ypV9pnAXJmhl2k5zCCFYKCpRHfnFdhaB+AYBtPqNT HK65Q787DhQnoVFVZCeFiU+X6A== X-Received: by 2002:aa7:84cc:: with SMTP id x12-v6mr5661502pfn.220.1539342721372; Fri, 12 Oct 2018 04:12:01 -0700 (PDT) Received: from localhost ([122.171.67.41]) by smtp.gmail.com with ESMTPSA id z7-v6sm1963133pff.146.2018.10.12.04.12.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 04:12:00 -0700 (PDT) From: Viresh Kumar To: ulf.hansson@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , niklas.cassel@linaro.org, rnayak@codeaurora.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 6/9] OPP: Add dev_pm_opp_{set|put}_genpd_device() helper Date: Fri, 12 Oct 2018 16:41:14 +0530 Message-Id: <110c9e13d8d44dfb59577256b1309dddf2ceda12.1539341929.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Multiple generic power domains for a consumer device are supported with the help of virtual devices, which are created for each consumer device - genpd pair. These are the device structures which are attached to the power domain and are required by the OPP core to set the performance state of the genpd. The helpers added by this commit are required to be called once for each of these virtual devices. These are required only if multiple domains are available for a device, otherwise the actual device structure will be used instead by the OPP core. The new helpers also support the complex cases where the consumer device wouldn't always require all the domains. For example, a camera may require only one power domain during normal operations but two during high resolution operations. The consumer driver can call dev_pm_opp_put_genpd_device(high_resolution_genpd_dev) if it is currently operating in the normal mode and doesn't have any performance requirements from the genpd which manages high resolution power requirements. The consumer driver can later call dev_pm_opp_set_genpd_device(high_resolution_genpd_dev) once it switches back to the high resolution mode. The new helpers differ from other OPP set/put helpers as the new ones can be called with OPPs initialized for the table as we may need to call them on the fly because of the complex case explained above. For this reason it is possible that the genpd_device structure may be used in parallel while the new helpers are running and a new mutex is added to protect against that. We didn't use the existing opp_table->lock mutex as that is widely used in the OPP core and we will need a lock in the hotpath now, i.e. while changing OPP and we need to make sure there is not much contention while doing that. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 88 ++++++++++++++++++++++++++++++++++++++++++ drivers/opp/of.c | 16 +++++++- drivers/opp/opp.h | 4 ++ include/linux/pm_opp.h | 8 ++++ 4 files changed, 115 insertions(+), 1 deletion(-) -- 2.18.0.rc1.242.g61856ae69a2c diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 02a69a62dac8..8d7bf9d83752 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -823,6 +823,7 @@ static struct opp_table *_allocate_opp_table(struct device *dev, int index) return NULL; mutex_init(&opp_table->lock); + mutex_init(&opp_table->genpd_dev_lock); INIT_LIST_HEAD(&opp_table->dev_list); opp_dev = _add_opp_dev(dev, opp_table); @@ -920,6 +921,7 @@ static void _opp_table_kref_release(struct kref *kref) _remove_opp_dev(opp_dev, opp_table); } + mutex_destroy(&opp_table->genpd_dev_lock); mutex_destroy(&opp_table->lock); list_del(&opp_table->node); kfree(opp_table); @@ -1602,6 +1604,92 @@ void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) } EXPORT_SYMBOL_GPL(dev_pm_opp_unregister_set_opp_helper); +/** + * dev_pm_opp_set_genpd_device - Set virtual genpd device for an index + * @dev: Consumer device for which the genpd device is getting set. + * @genpd_dev: virtual genpd device. + * @index: index. + * + * Multiple generic power domains for a device are supported with the help of + * virtual genpd devices, which are created for each consumer device - genpd + * pair. These are the device structures which are attached to the power domain + * and are required by the OPP core to set the performance state of the genpd. + * + * This helper will normally be called by the consumer driver of the device + * "dev", as only that has details of the genpd devices. + * + * This helper needs to be called once for each of those virtual devices, but + * only if multiple domains are available for a device. Otherwise the original + * device structure will be used instead by the OPP core. + */ +struct opp_table *dev_pm_opp_set_genpd_device(struct device *dev, + struct device *genpd_device, + int index) +{ + struct opp_table *opp_table; + + opp_table = dev_pm_opp_get_opp_table(dev); + if (!opp_table) + return ERR_PTR(-ENOMEM); + + mutex_lock(&opp_table->genpd_dev_lock); + + if (unlikely(!opp_table->genpd_devices || + index >= opp_table->required_opp_count || + opp_table->genpd_devices[index])) { + + dev_err(dev, "Invalid request to set required device\n"); + dev_pm_opp_put_opp_table(opp_table); + mutex_unlock(&opp_table->genpd_dev_lock); + + return ERR_PTR(-EINVAL); + } + + opp_table->genpd_devices[index] = genpd_device; + mutex_unlock(&opp_table->genpd_dev_lock); + + return opp_table; +} + +/** + * dev_pm_opp_put_genpd_device() - Releases resources blocked for genpd device. + * @opp_table: OPP table returned by dev_pm_opp_set_genpd_device(). + * @genpd_device: virtual genpd device. + * + * This releases the resource previously acquired with a call to + * dev_pm_opp_set_genpd_device(). The consumer driver shall call this helper if + * it doesn't want OPP core to update performance state of a power domain + * anymore. + */ +void dev_pm_opp_put_genpd_device(struct opp_table *opp_table, + struct device *genpd_device) +{ + int i; + + /* + * Acquire genpd_dev_lock to make sure genpd_device isn't getting used + * in parallel. + */ + mutex_lock(&opp_table->genpd_dev_lock); + + for (i = 0; i < opp_table->required_opp_count; i++) { + if (opp_table->genpd_devices[i] != genpd_device) + continue; + + opp_table->genpd_devices[i] = NULL; + dev_pm_opp_put_opp_table(opp_table); + + /* Drop the vote */ + dev_pm_genpd_set_performance_state(genpd_device, 0); + break; + } + + mutex_unlock(&opp_table->genpd_dev_lock); + + if (unlikely(i == opp_table->required_opp_count)) + dev_err(genpd_device, "Failed to find required device entry\n"); +} + /** * dev_pm_opp_add() - Add an OPP table from a table definitions * @dev: device for which we do this operation diff --git a/drivers/opp/of.c b/drivers/opp/of.c index ffaeefef98ce..fd67c9b55d7d 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -134,6 +134,7 @@ static struct opp_table *_find_table_of_opp_np(struct device_node *opp_np) static void _opp_table_free_required_tables(struct opp_table *opp_table) { struct opp_table **required_opp_tables = opp_table->required_opp_tables; + struct device **genpd_devices = opp_table->genpd_devices; int i; if (!required_opp_tables) @@ -147,8 +148,10 @@ static void _opp_table_free_required_tables(struct opp_table *opp_table) } kfree(required_opp_tables); + kfree(genpd_devices); opp_table->required_opp_count = 0; + opp_table->genpd_devices = NULL; opp_table->required_opp_tables = NULL; } @@ -161,6 +164,7 @@ static void _opp_table_alloc_required_tables(struct opp_table *opp_table, struct device_node *opp_np) { struct opp_table **required_opp_tables; + struct device **genpd_devices = NULL; struct device_node *required_np, *np; int count, i; @@ -175,11 +179,21 @@ static void _opp_table_alloc_required_tables(struct opp_table *opp_table, if (!count) goto put_np; + if (count > 1) { + genpd_devices = kcalloc(count, sizeof(*genpd_devices), + GFP_KERNEL); + if (!genpd_devices) + goto put_np; + } + required_opp_tables = kcalloc(count, sizeof(*required_opp_tables), GFP_KERNEL); - if (!required_opp_tables) + if (!required_opp_tables) { + kfree(genpd_devices); goto put_np; + } + opp_table->genpd_devices = genpd_devices; opp_table->required_opp_tables = required_opp_tables; opp_table->required_opp_count = count; diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 24b340ad18d1..aea69a24c26b 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -135,6 +135,8 @@ enum opp_table_access { * @parsed_static_opps: True if OPPs are initialized from DT. * @shared_opp: OPP is shared between multiple devices. * @suspend_opp: Pointer to OPP to be used during device suspend. + * @genpd_dev_lock: Mutex protecting the genpd device pointers. + * @genpd_devices: List of virtual devices for multiple genpd support. * @required_opp_tables: List of device OPP tables that are required by OPPs in * this table. * @required_opp_count: Number of required devices. @@ -177,6 +179,8 @@ struct opp_table { enum opp_table_access shared_opp; struct dev_pm_opp *suspend_opp; + struct mutex genpd_dev_lock; + struct device **genpd_devices; struct opp_table **required_opp_tables; unsigned int required_opp_count; diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 5d399eeef172..b14600ce078f 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -126,6 +126,8 @@ struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name); void dev_pm_opp_put_clkname(struct opp_table *opp_table); struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data)); void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table); +struct opp_table *dev_pm_opp_set_genpd_device(struct device *dev, struct device *genpd_device, int index); +void dev_pm_opp_put_genpd_device(struct opp_table *opp_table, struct device *genpd_device); int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq); int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask); int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); @@ -272,6 +274,12 @@ static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {} +static inline struct opp_table *dev_pm_opp_set_genpd_device(struct device *dev, struct device *genpd_device, int index) +{ + return ERR_PTR(-ENOTSUPP); +} + +static inline void dev_pm_opp_put_genpd_device(struct opp_table *opp_table, struct device *genpd_device) {} static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) { return -ENOTSUPP; From patchwork Fri Oct 12 11:11:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 148754 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp599119lji; Fri, 12 Oct 2018 04:12:09 -0700 (PDT) X-Google-Smtp-Source: ACcGV60FYpv3t7GytsmIEd+KJyNlnhVEiseHxcSVIPZesWBLEBT2FiN+2GjOFOyoc8v1OFlcVklF X-Received: by 2002:a63:a309:: with SMTP id s9-v6mr5137288pge.106.1539342728916; Fri, 12 Oct 2018 04:12:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539342728; cv=none; d=google.com; s=arc-20160816; b=I6S6Aunwv346QK1MaicNg/WibFQl3a1kWifSe8LIU6QA+8646EdTzq998Xgc9nsKKI NJk68zY1kPAr86XIeseG5S52/3QzNdnHj0WvEo7BsRvyHdzao7F/FeeQ1QyE1ewBEiFR aHRBm2nlF+4kxTjGug0ClKkRdCYFnusrrQ/Z5yGQD9pIUJ8S/X6hCsPCTv+7wz1vv65o u/wpPoi8VMC5vfs9UWHQ8pC+PRFgM9wrhErwfRxlVTAHelR6BxGfl2P5B9NmH+PK+qCm hONIU0eHYtUndsx73o2V1VFzFsFA8d68OCkxrD7OTsnrp3att2m1aUl3cw6czcdPaitx s2Kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=W7x0CiKb4U6qIR1zXs5ITgLcyJxUy+TLv0dVjSNwJic=; b=nlXio4SYUp35TtFKnjySEwwwoFmSg9OLaMWbZ5PSIbe277wmEVylT1avERnBzYxkwX onAXeDP8GOtvCzhoHB/8RJQ03zs4UE81VWiodMoolO/chDTJyd2HfKD552n4+5yBqPpT H67sz/WqHmUrl9qSFjsjeItlqMI0UnleR35rfsc8qtsx2Y5PZ42A2crNlhRKDSeOWNbn mzcGCHP7Cx8sPKoJIy+jW2AvBXJeAqnV8yyyEmJ7sYfUiuUu/xgVdM7pbLTslbkqoAYn bVWivySLo/1tp/ArAk6D33RAktaLQwAZmX95xYh9hQEZ2BLY9rVrgV4bfavoSNAHrwoi yojg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c70DCuhJ; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r198-v6si970181pgr.456.2018.10.12.04.12.08; Fri, 12 Oct 2018 04:12:08 -0700 (PDT) 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=@linaro.org header.s=google header.b=c70DCuhJ; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728566AbeJLSoC (ORCPT + 32 others); Fri, 12 Oct 2018 14:44:02 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:43478 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728489AbeJLSoA (ORCPT ); Fri, 12 Oct 2018 14:44:00 -0400 Received: by mail-pl1-f193.google.com with SMTP id 30-v6so5774750plb.10 for ; Fri, 12 Oct 2018 04:12:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=W7x0CiKb4U6qIR1zXs5ITgLcyJxUy+TLv0dVjSNwJic=; b=c70DCuhJCrcHCiyYNXpWSLjp8BDBV9DaDf//Lo+hMZKPWCOxggc1q/ZQjZBXoXvAmn VAsNNq6yprZTKf0ql4H2nTKcozARHVDW1l+Ao/aftttNEDOSPEoQRiKpXG3rJMmY7qEu qgZfMoRzRbahtlZm99W+CTUsS8QvPj0vNSc+k= 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; bh=W7x0CiKb4U6qIR1zXs5ITgLcyJxUy+TLv0dVjSNwJic=; b=r2KTAOI93lmeeEFQJr/pu+CX3TwQbMT2G1JF34zNyUI+vM1BHKRIxI/XXI2rjiHci6 bLQqog4I/Fn6v8SEhwYo+MOZwJBCqSice2ph9fL3w5mcxKrVgVpp3o1LzExLMgBm+7G+ q5M1t5WYdvqypJAgsLLDwmI1AO6E6WrB/260SvYo/uBzo2BiPxfDMMYd34e+E5R39/29 fuGEA+WSoxGWSDhF/mNfI8mwdCmzmGP/R6Ylf4p1KnEpI1I/E864Z200b2Y6LSiLxlTR C+4iAuk7FyYXF4MIwbYHpFOJa3SBZtkZ/bQuzJG75MQNyTt244AjeEGcM4X+PIhavk7X xRJQ== X-Gm-Message-State: ABuFfojjvEwGexDHa6AQjtL3bOoeAaF3pVOBof3m/VKmVxyrpAoSj3ip QBIpaIChuBr/rcFRRzEtzmPJGg== X-Received: by 2002:a17:902:8342:: with SMTP id z2-v6mr5428232pln.147.1539342724696; Fri, 12 Oct 2018 04:12:04 -0700 (PDT) Received: from localhost ([122.171.67.41]) by smtp.gmail.com with ESMTPSA id q21-v6sm5728065pfq.51.2018.10.12.04.12.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 04:12:04 -0700 (PDT) From: Viresh Kumar To: ulf.hansson@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Rafael Wysocki , niklas.cassel@linaro.org, rnayak@codeaurora.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 7/9] OPP: Configure all required OPPs Date: Fri, 12 Oct 2018 16:41:15 +0530 Message-Id: X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that all the infrastructure is in place to support multiple required OPPs, lets switch over to using it. A new internal routine _set_required_opps() takes care of updating performance state for all the required OPPs. With this the performance state updates are supported even when the end device needs to configure regulators as well, that wasn't the case earlier. The pstates were earlier stored in the end device's OPP structures, that also changes now as those values are stored in the genpd's OPP structures. And so we switch over to using genpd_opp_to_performance_state() instead of of_genpd_opp_to_performance_state() to get performance state for the genpd OPPs. The routine _generic_set_opp_domain() is not required anymore and is removed. On errors we don't try to recover by reverting to old settings as things are really complex now and the calls here should never really fail unless there is a bug. There is no point increasing the complexity, for code which will never be executed. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 113 ++++++++++++++++++++++++++------------------- drivers/opp/of.c | 5 +- 2 files changed, 68 insertions(+), 50 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 8d7bf9d83752..1eeb89ab9a68 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -548,44 +548,6 @@ _generic_set_opp_clk_only(struct device *dev, struct clk *clk, return ret; } -static inline int -_generic_set_opp_domain(struct device *dev, struct clk *clk, - unsigned long old_freq, unsigned long freq, - unsigned int old_pstate, unsigned int new_pstate) -{ - int ret; - - /* Scaling up? Scale domain performance state before frequency */ - if (freq > old_freq) { - ret = dev_pm_genpd_set_performance_state(dev, new_pstate); - if (ret) - return ret; - } - - ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq); - if (ret) - goto restore_domain_state; - - /* Scaling down? Scale domain performance state after frequency */ - if (freq < old_freq) { - ret = dev_pm_genpd_set_performance_state(dev, new_pstate); - if (ret) - goto restore_freq; - } - - return 0; - -restore_freq: - if (_generic_set_opp_clk_only(dev, clk, freq, old_freq)) - dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n", - __func__, old_freq); -restore_domain_state: - if (freq > old_freq) - dev_pm_genpd_set_performance_state(dev, old_pstate); - - return ret; -} - static int _generic_set_opp_regulator(const struct opp_table *opp_table, struct device *dev, unsigned long old_freq, @@ -663,6 +625,56 @@ static int _set_opp_custom(const struct opp_table *opp_table, return opp_table->set_opp(data); } +/* This is only called for PM domain for now */ +static int _set_required_opps(struct device *dev, + struct opp_table *opp_table, + struct dev_pm_opp *opp) +{ + struct opp_table **required_opp_tables = opp_table->required_opp_tables; + struct device **genpd_devices = opp_table->genpd_devices; + unsigned int pstate; + int i, ret = 0; + + if (!required_opp_tables) + return 0; + + /* Single genpd case */ + if (!genpd_devices) { + pstate = opp->required_opps[0]->pstate; + ret = dev_pm_genpd_set_performance_state(dev, pstate); + if (ret) { + dev_err(dev, "Failed to set performance state of %s: %d (%d)\n", + dev_name(dev), pstate, ret); + } + return ret; + } + + /* Multiple genpd case */ + + /* + * Acquire genpd_dev_lock to make sure we don't use a genpd_dev after it + * is freed from another thread. + */ + mutex_lock(&opp_table->genpd_dev_lock); + + for (i = 0; i < opp_table->required_opp_count; i++) { + pstate = opp->required_opps[i]->pstate; + + if (!genpd_devices[i]) + continue; + + ret = dev_pm_genpd_set_performance_state(genpd_devices[i], pstate); + if (ret) { + dev_err(dev, "Failed to set performance rate of %s: %d (%d)\n", + dev_name(genpd_devices[i]), pstate, ret); + break; + } + } + mutex_unlock(&opp_table->genpd_dev_lock); + + return ret; +} + /** * dev_pm_opp_set_rate() - Configure new OPP based on frequency * @dev: device for which we do this operation @@ -730,6 +742,13 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) dev_dbg(dev, "%s: switching OPP: %lu Hz --> %lu Hz\n", __func__, old_freq, freq); + /* Scaling up? Configure required OPPs before frequency */ + if (freq > old_freq) { + ret = _set_required_opps(dev, opp_table, opp); + if (ret) + goto put_opp; + } + if (opp_table->set_opp) { ret = _set_opp_custom(opp_table, dev, old_freq, freq, IS_ERR(old_opp) ? NULL : old_opp->supplies, @@ -740,19 +759,17 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) opp->supplies); } else { /* Only frequency scaling */ + ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq); + } - /* - * We don't support devices with both regulator and - * domain performance-state for now. - */ - if (opp_table->genpd_performance_state) - ret = _generic_set_opp_domain(dev, clk, old_freq, freq, - IS_ERR(old_opp) ? 0 : old_opp->pstate, - opp->pstate); - else - ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq); + /* Scaling down? Configure required OPPs after frequency */ + if (!ret && freq < old_freq) { + ret = _set_required_opps(dev, opp_table, opp); + if (ret) + dev_err(dev, "Failed to set required opps: %d\n", ret); } +put_opp: dev_pm_opp_put(opp); put_old_opp: if (!IS_ERR(old_opp)) diff --git a/drivers/opp/of.c b/drivers/opp/of.c index fd67c9b55d7d..f4e8895542ca 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -595,12 +595,13 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table, if (!of_property_read_u32(np, "clock-latency-ns", &val)) new_opp->clock_latency_ns = val; - new_opp->pstate = of_genpd_opp_to_performance_state(dev, np); - ret = opp_parse_supplies(new_opp, dev, opp_table); if (ret) goto free_required_opps; + if (opp_table->is_genpd) + new_opp->pstate = genpd_opp_to_performance_state(dev, new_opp); + ret = _opp_add(dev, new_opp, opp_table, rate_not_available); if (ret) { /* Don't return error for duplicate OPPs */ From patchwork Fri Oct 12 11:11:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 148755 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp599173lji; Fri, 12 Oct 2018 04:12:12 -0700 (PDT) X-Google-Smtp-Source: ACcGV635nKBhiOPVdDlQgTh4pY0yE3nfCvAquzqA19xgwtGQ0bvOn9HRZz9KDMqKuWZQSD7iyIZF X-Received: by 2002:a17:902:5e3:: with SMTP id f90-v6mr5643182plf.286.1539342731996; Fri, 12 Oct 2018 04:12:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539342731; cv=none; d=google.com; s=arc-20160816; b=GE22DqE0zOwTqexT5Nw+Mg4DFcqNNQxCJfUQi3P7Vdi5SXuy2hkXh1GcIsICsN9JeP 7wSrSeimEYNrevI1ZMXHr9vv8v9D5XRqng+FozBPaN6QrUHFvMEm+I2FIx9pjnLvmKAe NP8NnLsRKBxbannRF+SjYpBM43choxTzHvpxLQo15mo9JWZvLQuISVzvQhMUJ0wbTlNd n0NR6MkNmBtxnYmAAun5S/T4XlxM8kMt66lOmPrhp22RtBTBXnLXaDnplpB+c/q9sASb u/3vfpwg1WJrAPBdabMr4Nwnrbr/6Nsu3rKC5HAVovDHYxWttqT2FRDuSguEq94xwibs jaJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=tFludSDWfmu59Yda7wPTpBXSCzbJ9HkYZfHCRf1lMuA=; b=Klj4Cf1ocW7+KSDA8CW3kZSGqosAMV/ooLqSuxQop7I1yOk4oe+gwYhPYnHhak6KKA XIjqtzAI4+1pLwVsueNq3FsdCIeNG0XQikH9kuMqeYYZotsImq51X0INRDbiwSDAqVdt nAWgiQQhVbLKUPo0/nfeWndJQe0ByGYTNCiQBx9rnwtUczTBapPrZgy7o2WFh3eVraJX 8WXZoOLXLnWj4IW/rpmscjF5uxVk4O46JHQJGqazMo1BE4eJsb8l2+Yi61hDgjab8BvN g6orTVoa7o7DAuFze7/Em8kDD5ovPK6aAhIDRWcSTwlGMb8K+BhAbSLhFvnpL601Z5PD N3eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Jmt2y/NC"; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r198-v6si970181pgr.456.2018.10.12.04.12.11; Fri, 12 Oct 2018 04:12:11 -0700 (PDT) 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=@linaro.org header.s=google header.b="Jmt2y/NC"; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728585AbeJLSoF (ORCPT + 32 others); Fri, 12 Oct 2018 14:44:05 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:46243 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728489AbeJLSoE (ORCPT ); Fri, 12 Oct 2018 14:44:04 -0400 Received: by mail-pl1-f195.google.com with SMTP id v5-v6so5775582plz.13 for ; Fri, 12 Oct 2018 04:12:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tFludSDWfmu59Yda7wPTpBXSCzbJ9HkYZfHCRf1lMuA=; b=Jmt2y/NCLwN416KNrQMN17HrZZlZnY2TvYunD+RbJmi2hIvKbxFBH1DopThfxTEpwp z6cLd3UkobbUBsvKWvsVZHvjZAs0cYQ3kcynbVaEtT7Po28AWAy1X8Mh19Hk2qqTzxPU n8OXeTSsdTIqdLThOplthf9IGJCIWRwrSp8eA= 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; bh=tFludSDWfmu59Yda7wPTpBXSCzbJ9HkYZfHCRf1lMuA=; b=kY+Kotrgxxbhc6/dWK7Nv0bY3DvVneWvQFVlHa599VtrVbIxp/64jv1dLnKgYES913 XXVYFaKmgEqfpHGlP+cFR7TeVKDFQdQLBFkpdk1UNe2BtBmLvFJwitzeKbjH7nbA4odM 7sgVANgn1JNSaXAUrX2mXHMuw8GMBiPZIr5YS0v/uOyRO1/Q3WVyAUHapQTSPVi+vTMo bOTmozbUl6z/Z6ToIKVcgsIZOceHITuhLDmUlJdw3YwL7ea/HciRPamkroG84c3ZbRha sx1EirQnw2wBCwTI/QxK6p6yLQOTy47jYG8koDVjABLbJPG8GXdVeGDg//sJzIMowGGK 9v4A== X-Gm-Message-State: ABuFfohAVyAEy7uycfc8glSOpQ9vNi8ejkLl0Ud58c4giMyH5ZA4QL++ AFogbaRlotHfni5BfLSHwkRXWg== X-Received: by 2002:a17:902:3a2:: with SMTP id d31-v6mr5496193pld.287.1539342728164; Fri, 12 Oct 2018 04:12:08 -0700 (PDT) Received: from localhost ([122.171.67.41]) by smtp.gmail.com with ESMTPSA id l83-v6sm3043645pfi.172.2018.10.12.04.12.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 04:12:07 -0700 (PDT) From: Viresh Kumar To: ulf.hansson@linaro.org, "Rafael J. Wysocki" , Kevin Hilman , Pavel Machek , Len Brown , Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , niklas.cassel@linaro.org, rnayak@codeaurora.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 8/9] OPP: Rename and relocate of_genpd_opp_to_performance_state() Date: Fri, 12 Oct 2018 16:41:16 +0530 Message-Id: X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The OPP core already has the performance state values for each of the genpd's OPPs and there is no need to call the genpd callback again to get the performance state for the case where the end device doesn't have an OPP table and has the "required-opps" property directly in its node. This commit renames of_genpd_opp_to_performance_state() as of_get_required_opp_performance_state() and moves it to the OPP core, as it is all about OPP stuff now. Signed-off-by: Viresh Kumar --- drivers/base/power/domain.c | 48 ------------------------------------- drivers/opp/of.c | 44 ++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 9 ------- include/linux/pm_opp.h | 5 ++++ 4 files changed, 49 insertions(+), 57 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 2c82194d2a30..55f3a172f6b4 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2547,54 +2547,6 @@ unsigned int genpd_opp_to_performance_state(struct device *genpd_dev, } EXPORT_SYMBOL_GPL(genpd_opp_to_performance_state); -/** - * of_genpd_opp_to_performance_state- Gets performance state of device's - * power domain corresponding to a DT node's "required-opps" property. - * - * @dev: Device for which the performance-state needs to be found. - * @np: DT node where the "required-opps" property is present. This can be - * the device node itself (if it doesn't have an OPP table) or a node - * within the OPP table of a device (if device has an OPP table). - * - * Returns performance state corresponding to the "required-opps" property of - * a DT node. This calls platform specific genpd->opp_to_performance_state() - * callback to translate power domain OPP to performance state. - * - * Returns performance state on success and 0 on failure. - */ -unsigned int of_genpd_opp_to_performance_state(struct device *dev, - struct device_node *np) -{ - struct generic_pm_domain *genpd; - struct dev_pm_opp *opp; - int state = 0; - - genpd = dev_to_genpd(dev); - if (IS_ERR(genpd)) - return 0; - - if (unlikely(!genpd->set_performance_state)) - return 0; - - genpd_lock(genpd); - - opp = of_dev_pm_opp_find_required_opp(&genpd->dev, np); - if (IS_ERR(opp)) { - dev_err(dev, "Failed to find required OPP: %ld\n", - PTR_ERR(opp)); - goto unlock; - } - - state = genpd->opp_to_performance_state(genpd, opp); - dev_pm_opp_put(opp); - -unlock: - genpd_unlock(genpd); - - return state; -} -EXPORT_SYMBOL_GPL(of_genpd_opp_to_performance_state); - static int __init genpd_bus_init(void) { return bus_register(&genpd_bus_type); diff --git a/drivers/opp/of.c b/drivers/opp/of.c index f4e8895542ca..b059d833f920 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -969,6 +969,50 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, } EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus); +/** + * of_get_required_opp_performance_state() - Search for required OPP and return its performance state. + * @np: Node that contains the "required-opps" property. + * @index: Index of the phandle to parse. + * + * Returns the performance state of the OPP pointed out by the "required-opps" + * property at @index in @np. + * + * Return: Positive performance state on success, otherwise 0 on errors. + */ +unsigned int of_get_required_opp_performance_state(struct device_node *np, + int index) +{ + struct dev_pm_opp *opp; + struct device_node *required_np; + struct opp_table *opp_table; + unsigned int pstate = 0; + + required_np = of_parse_required_opp(np, index); + if (!required_np) + return -ENODEV; + + opp_table = _find_table_of_opp_np(required_np); + if (IS_ERR(opp_table)) { + pr_err("%s: Failed to find required OPP table %pOF: %ld\n", + __func__, np, PTR_ERR(opp_table)); + goto put_required_np; + } + + opp = _find_opp_of_np(opp_table, required_np); + if (opp) { + pstate = opp->pstate; + dev_pm_opp_put(opp); + } + + dev_pm_opp_put_opp_table(opp_table); + +put_required_np: + of_node_put(required_np); + + return pstate; +} +EXPORT_SYMBOL_GPL(of_get_required_opp_performance_state); + /** * of_dev_pm_opp_find_required_opp() - Search for required OPP. * @dev: The device whose OPP node is referenced by the 'np' DT node. diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index e03f300f7468..80672bcb1216 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -235,8 +235,6 @@ int of_genpd_parse_idle_states(struct device_node *dn, struct genpd_power_state **states, int *n); unsigned int genpd_opp_to_performance_state(struct device *genpd_dev, struct dev_pm_opp *opp); -unsigned int of_genpd_opp_to_performance_state(struct device *dev, - struct device_node *np); int genpd_dev_pm_attach(struct device *dev); struct device *genpd_dev_pm_attach_by_id(struct device *dev, @@ -282,13 +280,6 @@ genpd_opp_to_performance_state(struct device *genpd_dev, struct dev_pm_opp *opp) return 0; } -static inline unsigned int -of_genpd_opp_to_performance_state(struct device *dev, - struct device_node *np) -{ - return 0; -} - static inline int genpd_dev_pm_attach(struct device *dev) { return 0; diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index b14600ce078f..f440e625f1fd 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -315,6 +315,7 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpuma struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev); struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev, struct device_node *np); struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp); +unsigned int of_get_required_opp_performance_state(struct device_node *np, int index); #else static inline int dev_pm_opp_of_add_table(struct device *dev) { @@ -357,6 +358,10 @@ static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp) { return NULL; } +static inline unsigned int of_get_required_opp_performance_state(struct device_node *np, int index) +{ + return 0; +} #endif #endif /* __LINUX_OPP_H__ */ From patchwork Fri Oct 12 11:11:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 148756 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp599248lji; Fri, 12 Oct 2018 04:12:15 -0700 (PDT) X-Google-Smtp-Source: ACcGV62OPXbWyFA9F7hXn5KiMsUe4kpnw4okYm9m75gmUtoZjSgEVX+4gHnxRi5LnuwYj7e5dSit X-Received: by 2002:a17:902:64c2:: with SMTP id y2-v6mr5486514pli.35.1539342735294; Fri, 12 Oct 2018 04:12:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539342735; cv=none; d=google.com; s=arc-20160816; b=RzpGuEIxV2hu0eoEWQ6DJAgzX8I/A3aOmfjOeLtaBgkTesk+MDXBSc6AhbuJKs5uZD R23/syfRTGgpF54Q4SkSObU7q6h9h4sjZmpt4QADlbJw+Te7QOIvvVrV/UYhlQyxtLwi ZLwwdHVy1F/uTZEQH5j2ZirNaofcvajFiEt+6QHlb0oRB6SEAwnZ/rZo0ebIGvFrckEI tCxGrMW2yxjmCUOPwF/7eO6RwTziMq1EOhWdgtxKYzTNAkZq6oZaLC3FAgXEma2nxdjv FSfNet0it1ItIrhy7BTGSF7Uulw2rNybPn7GBFqukWdZ5VfjVqpxr+anxyZ3w74wo5wr 8J2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=akQeUpsf7fkn8621Db/E2werSvh2FTMXzqxwQvFVpBE=; b=B5wvv8f5s7YdvwoZCk5bMa9oIINw4wQpogFSgyjEjJ5WTXHUdU+soPzolH0u9KbYCK o7+7ZItg13KVi2hGPB4aDPoQxDJamxj8J/Ngg/2CWNaIZOA867ApzUNehnsBCEI/xdHl vobUKGcrjGhXDjbiX+i1SZ396hVOH/7cN1r8BU9L6rzw3cxZoqW3h8n2sbLiNuOsutZR 4t+H+K8sYrl7GeWpum9VegN8rsQl5jh9biB/yRThA8m3qI6e00i+ZURNZjpKd+W7h9Ik pwrkCPVD85YOci2QGhJMHk5Y9fddXKVVSLEPoa6iRlMuKZuyefas8cq0VlksbPzVqxr4 OZsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WBAA+tT9; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a135-v6si1108035pfd.241.2018.10.12.04.12.14; Fri, 12 Oct 2018 04:12:15 -0700 (PDT) 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=@linaro.org header.s=google header.b=WBAA+tT9; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728633AbeJLSoI (ORCPT + 32 others); Fri, 12 Oct 2018 14:44:08 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:38665 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728606AbeJLSoH (ORCPT ); Fri, 12 Oct 2018 14:44:07 -0400 Received: by mail-pf1-f193.google.com with SMTP id f29-v6so6040247pff.5 for ; Fri, 12 Oct 2018 04:12:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=akQeUpsf7fkn8621Db/E2werSvh2FTMXzqxwQvFVpBE=; b=WBAA+tT98s2CgT/WkXpszZlqtqAppwvmI8+XNAJXW9xjFpM4rp7i3xiRBZUgf/WqkW uBhmw4n0KxkZeG1xcyDqDLyg6WeJit6/aIBrdXlrktTRx+1/uZRK6g7fJiLG2o15vpfi SCZH1LOy1R1LlCFg2UX8BmzAXYk4Soeg9YF1k= 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; bh=akQeUpsf7fkn8621Db/E2werSvh2FTMXzqxwQvFVpBE=; b=dO4qF3to/MH8ptGPt28KMmRhJ+rtNpWSaqrgMWW7D8SLaw4/Wmtrb2u42NeuYgpl/L eR4ppyNFsxmWlfNBngpXe7FA6LtiS9XErd6L6L9obydqcdOrUEPUiRXDYJLcYGG4ceDx 7Q/vKp2CNTkbVip3l2Ok18TZmKMJJs6Dgjr5k2sCisvR3pV3dfQxbHGreU96zNVsRU/5 ElcFeKeHTnSS1pJNnznUp7SkXzOdPwGTqlOx/cchd2DSIOfxYWNqX0j/hjK/86SVSa60 NIXZ6ZV3zWcBthj5+D314efpQeGU4y55a1X5U5JPvQxP1Vxj2urq49fL29U48+ttROAv NmhA== X-Gm-Message-State: ABuFfoiwLQhgmju+dinmdgwRShB1Kfneurkx+DsD9e/quFm7Oq2nJE2m qw3VSVSG2cjZBkrAADeksAbR5g== X-Received: by 2002:a65:45c9:: with SMTP id m9-v6mr5046699pgr.212.1539342731845; Fri, 12 Oct 2018 04:12:11 -0700 (PDT) Received: from localhost ([122.171.67.41]) by smtp.gmail.com with ESMTPSA id v83-v6sm4510860pfa.103.2018.10.12.04.12.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 04:12:11 -0700 (PDT) From: Viresh Kumar To: ulf.hansson@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , niklas.cassel@linaro.org, rnayak@codeaurora.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 9/9] OPP: Remove of_dev_pm_opp_find_required_opp() Date: Fri, 12 Oct 2018 16:41:17 +0530 Message-Id: X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This isn't used anymore, remove it. Signed-off-by: Viresh Kumar --- drivers/opp/of.c | 54 ------------------------------------------ include/linux/pm_opp.h | 5 ---- 2 files changed, 59 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c diff --git a/drivers/opp/of.c b/drivers/opp/of.c index b059d833f920..623f651f9e11 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -1013,60 +1013,6 @@ unsigned int of_get_required_opp_performance_state(struct device_node *np, } EXPORT_SYMBOL_GPL(of_get_required_opp_performance_state); -/** - * of_dev_pm_opp_find_required_opp() - Search for required OPP. - * @dev: The device whose OPP node is referenced by the 'np' DT node. - * @np: Node that contains the "required-opps" property. - * - * Returns the OPP of the device 'dev', whose phandle is present in the "np" - * node. Although the "required-opps" property supports having multiple - * phandles, this helper routine only parses the very first phandle in the list. - * - * Return: Matching opp, else returns ERR_PTR in case of error and should be - * handled using IS_ERR. - * - * The callers are required to call dev_pm_opp_put() for the returned OPP after - * use. - */ -struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev, - struct device_node *np) -{ - struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ENODEV); - struct device_node *required_np; - struct opp_table *opp_table; - - opp_table = _find_opp_table(dev); - if (IS_ERR(opp_table)) - return ERR_CAST(opp_table); - - required_np = of_parse_phandle(np, "required-opps", 0); - if (unlikely(!required_np)) { - dev_err(dev, "Unable to parse required-opps\n"); - goto put_opp_table; - } - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->available && temp_opp->np == required_np) { - opp = temp_opp; - - /* Increment the reference count of OPP */ - dev_pm_opp_get(opp); - break; - } - } - - mutex_unlock(&opp_table->lock); - - of_node_put(required_np); -put_opp_table: - dev_pm_opp_put_opp_table(opp_table); - - return opp; -} -EXPORT_SYMBOL_GPL(of_dev_pm_opp_find_required_opp); - /** * dev_pm_opp_get_of_node() - Gets the DT node corresponding to an opp * @opp: opp for which DT node has to be returned for diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index f440e625f1fd..fdd87a21dac4 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -313,7 +313,6 @@ int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask); void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask); int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev); -struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev, struct device_node *np); struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp); unsigned int of_get_required_opp_performance_state(struct device_node *np, int index); #else @@ -350,10 +349,6 @@ static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device return NULL; } -static inline struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev, struct device_node *np) -{ - return NULL; -} static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp) { return NULL;