From patchwork Thu Jan 28 07:00:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 372524 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp960499jam; Wed, 27 Jan 2021 23:01:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJzRWt7twPw/Zsu8Ny32BmsDhGIfYhNozKaSpLwaledCV+zYAe/aisBQpaRhx2PH9il3lh8U X-Received: by 2002:a50:c34b:: with SMTP id q11mr12739738edb.173.1611817261474; Wed, 27 Jan 2021 23:01:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611817261; cv=none; d=google.com; s=arc-20160816; b=hcf6hk7QwKhXMb1Axy6wNd71N5wIaAj9N6oUcGZjAqNA4uxIBSXX1g3VQ1iKzh442n Y1rU7YGjWSVKja2mF0kDFpy6GBGELd8kocwq3yRFODx2YhupRDBJ46xTWQTebp3zCmEb j9f1/gY9je9Ijj6vJI4AyRk+MD7rq8kxR6PYcrBgOE+MZqQEttu8xWJkzSVkFxt40tD5 M4M9boPjkn/y/taRbk4BgCBc9jJ9UgcAYuLMGB7bh2PiLS4JMoyjxfbornsSZTr3oeNF mczAfG5xsS5TLYyrQ5O3CYdelROdYITR7TRSRSuo9ezn3D2uC3Mt3YuNEAXoFCEsrb9F A06w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=5/az9vJJKvmVOYVTxpGhyp9BVL4fKFn3/tkkqVwm4EE=; b=LmCqtnJ5QBiL5b8I8vM7zNgKh9LgMnBr72LWkTGXlTJcpR/RGJHwjH8zJr3RZKhs5f +IcZmnNFLcRbs/QqsJQ0eGy7dkYoBbFrUHVGSPlToZWPjBChJSES/2/NesRGHg0Qqp58 XFfCsx+DS1dfoxzGOWQ0TfI6f8TIUHEbM6GcaH+O/9rqOOfCUfu/Gmwm7AIiebYu7wOe FLyWhTij603CZfARbYkSHCE2PjY+SvJp9O6fxSkaX0h+w+WID3+0MxoJnXyRlqynt5nT sKi8VVYGgn339GLOtJEDbScTo9nNSakJt/LFO4A2AGDMl0/YyDeCMkAaF2mMZhx5vPIR 8cQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OYHLeJvJ; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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. [23.128.96.18]) by mx.google.com with ESMTP id f10si2086060ejr.536.2021.01.27.23.01.01; Wed, 27 Jan 2021 23:01:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OYHLeJvJ; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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 S229774AbhA1HBA (ORCPT + 7 others); Thu, 28 Jan 2021 02:01:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229676AbhA1HA7 (ORCPT ); Thu, 28 Jan 2021 02:00:59 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03CEBC061574 for ; Wed, 27 Jan 2021 23:00:19 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id v19so3655147pgj.12 for ; Wed, 27 Jan 2021 23:00:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5/az9vJJKvmVOYVTxpGhyp9BVL4fKFn3/tkkqVwm4EE=; b=OYHLeJvJ79zb8hTo6KJmqeevrBj7uphPKvhzq5FcHZoQNm/yUs99TH8fvKXJuEQnhl xDIYpgf5EQAo8ikr34NJqRRwPygEFqtEgs68qy0dgtj8freOMSijibFKuxGOpmN3RXS6 5yEV2EJOyeAAQq1nfKuJJTdWmePkgE7uUeBOJmi9hhueLVIAzjg5K9F0C2FzqOKL1Kgl MzjFfkV97PH8vrmCSN7e6FZvT8+iFx2nZrLJ5bqf1qYwflZrml+i1Zmm0hdku47VrGnl hKk412NM2vWcQLX846T6ZUjRoc2Kd2SGSfCrh858MstLf6JF+Oet9jzGWKJrDsQUSD5p r03g== 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=5/az9vJJKvmVOYVTxpGhyp9BVL4fKFn3/tkkqVwm4EE=; b=YRAQdSxexFlDOOsviFbiiK9HkexCvX+fW3hOQrHn0h/cWZqJ8tAABuZ5YlRpN1ysng yknkl7ANy9nEomwzp8IrO9IUYP78jxBwGGLQYweijP3VkYRBurduPUAb5gEnC7eTNeOG F6KaSVlDKHDVTnMNF2bp1TsKSYWkAMBN8q37zulQrBo3gn54Ba/xIxn76Hun6Hap6Qey 2NwfGcjYJgtYnDrVO0QwZ+iWXWC/RlYxdvoHbGlx7O3gfZpAgN3aNpjSjSRhrAsyXtAi 5yy7UBxBF5K3YOD423xbDOZy2lJ4AkvMisXwWBiY5xAwTK1ou6lTpjA6maD2PYJ3Nr1W Rpbw== X-Gm-Message-State: AOAM533KpTFbJJU3EDwDcHwgS8TZmva/yO644UcC+NHuo8ArNm6hMbHC j7HBKMsSRresP/v2kQiXwNaYUA== X-Received: by 2002:a63:464a:: with SMTP id v10mr15401609pgk.393.1611817218478; Wed, 27 Jan 2021 23:00:18 -0800 (PST) Received: from localhost ([122.172.59.240]) by smtp.gmail.com with ESMTPSA id s21sm3967791pjz.13.2021.01.27.23.00.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jan 2021 23:00:17 -0800 (PST) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Rafael Wysocki , Dmitry Osipenko , linux-kernel@vger.kernel.org Subject: [PATCH V2 1/3] opp: Create _of_add_table_indexed() to reduce code duplication Date: Thu, 28 Jan 2021 12:30:07 +0530 Message-Id: <1b58a72fa4d6aadc9542a66f8150150534752d81.1611817096.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The implementation of dev_pm_opp_of_add_table() and dev_pm_opp_of_add_table_indexed() are almost identical. Create _of_add_table_indexed() to reduce code redundancy. Also remove the duplication of the doc style comments by referring to dev_pm_opp_of_add_table() from dev_pm_opp_of_add_table_indexed(). Signed-off-by: Viresh Kumar --- V2: - No change drivers/opp/of.c | 81 ++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 48 deletions(-) -- 2.25.0.rc1.19.g042ed3e048af diff --git a/drivers/opp/of.c b/drivers/opp/of.c index d0c0336be39b..c6856dcf4c34 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -956,29 +956,23 @@ static int _of_add_opp_table_v1(struct device *dev, struct opp_table *opp_table) return ret; } -/** - * dev_pm_opp_of_add_table() - Initialize opp table from device tree - * @dev: device pointer used to lookup OPP table. - * - * Register the initial OPP table with the OPP library for given device. - * - * Return: - * 0 On success OR - * Duplicate OPPs (both freq and volt are same) and opp->available - * -EEXIST Freq are same and volt are different OR - * Duplicate OPPs (both freq and volt are same) and !opp->available - * -ENOMEM Memory allocation failure - * -ENODEV when 'operating-points' property is not found or is invalid data - * in device node. - * -ENODATA when empty 'operating-points' property is found - * -EINVAL when invalid entries are found in opp-v2 table - */ -int dev_pm_opp_of_add_table(struct device *dev) +static int _of_add_table_indexed(struct device *dev, int index) { struct opp_table *opp_table; - int ret; + int ret, count; - opp_table = _add_opp_table_indexed(dev, 0); + if (index) { + /* + * If only one phandle is present, then the same OPP table + * applies for all index requests. + */ + count = of_count_phandle_with_args(dev->of_node, + "operating-points-v2", NULL); + if (count == 1) + index = 0; + } + + opp_table = _add_opp_table_indexed(dev, index); if (IS_ERR(opp_table)) return PTR_ERR(opp_table); @@ -996,15 +990,12 @@ int dev_pm_opp_of_add_table(struct device *dev) return ret; } -EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table); /** - * dev_pm_opp_of_add_table_indexed() - Initialize indexed opp table from device tree + * dev_pm_opp_of_add_table() - Initialize opp table from device tree * @dev: device pointer used to lookup OPP table. - * @index: Index number. * - * Register the initial OPP table with the OPP library for given device only - * using the "operating-points-v2" property. + * Register the initial OPP table with the OPP library for given device. * * Return: * 0 On success OR @@ -1017,31 +1008,25 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table); * -ENODATA when empty 'operating-points' property is found * -EINVAL when invalid entries are found in opp-v2 table */ -int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) +int dev_pm_opp_of_add_table(struct device *dev) { - struct opp_table *opp_table; - int ret, count; - - if (index) { - /* - * If only one phandle is present, then the same OPP table - * applies for all index requests. - */ - count = of_count_phandle_with_args(dev->of_node, - "operating-points-v2", NULL); - if (count == 1) - index = 0; - } - - opp_table = _add_opp_table_indexed(dev, index); - if (IS_ERR(opp_table)) - return PTR_ERR(opp_table); - - ret = _of_add_opp_table_v2(dev, opp_table); - if (ret) - dev_pm_opp_put_opp_table(opp_table); + return _of_add_table_indexed(dev, 0); +} +EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table); - return ret; +/** + * dev_pm_opp_of_add_table_indexed() - Initialize indexed opp table from device tree + * @dev: device pointer used to lookup OPP table. + * @index: Index number. + * + * Register the initial OPP table with the OPP library for given device only + * using the "operating-points-v2" property. + * + * Return: Refer to dev_pm_opp_of_add_table() for return values. + */ +int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) +{ + return _of_add_table_indexed(dev, index); } EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_indexed); From patchwork Thu Jan 28 07:00:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 372525 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp961683jam; Wed, 27 Jan 2021 23:02:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7YY1KIsfbUw/EVXXQOxOf67i7LGxgkiUYvi+t3T8Eygt1y6wa0NSNG8Rvz3FPt8Vi59DY X-Received: by 2002:a05:6402:270e:: with SMTP id y14mr9511300edd.322.1611817340514; Wed, 27 Jan 2021 23:02:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611817340; cv=none; d=google.com; s=arc-20160816; b=QKkI760aMMdcW/EWKXyhO0O9qxf6zke+WjiSLx/AdbSsSh8q+aIO3JTb5WupEiIuf2 rlKatPf5JZsJwntXPzI7lXTUvlSzCFiTubxZ56rXdyXcyb2RpCLcDFosP1/xFi++7X+N m6oYeWXzm4oYLIPSNjiiIe/PzdujhJ/VOcD8XZ89Fh7IPXRpuI3r/+WJe47dBHYPVfKD YQNcVkI2Suu6819ZKbTeTHNCDBfYfLL9sgyObR76DNejxzVVYFF+Y8jXFzNkNQ5xCMOV HEplyG/bYWITsPtqNUOoAjbDokCNSBW+ifPwWQuyRl/20hkd61LHVCeLrqUXC0/43UC2 wG5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ahYJzfuIo0e0JMYan7FcQvKFG+Ou8KUaBl9Hz3G4Bjc=; b=ll8S8MW0F3TSDZxoUcUJV3k75cSGYDDIvOe4YaIvIWxeSItS6i00fbEW+KPDyegwkA rUT+GFPEzxIXijEIi6sHvze4m8OcIUVtvlVIwLMJvkfAyCFY8inXJc+ysBc1YLlrD/PX qv1NS1Pr89NN4mbRm4sOyJDGmAKAOLuG4YnRPCu751qxrligzmlwsDRDOZSsSXyYKOZP IdevEUFpWvTijbR70qXoYHkMMWFO4KCqE5uClWJI6TcKupwFnMiCdJA+75suxMemAGlX D9T0fIVxMzelhocdpibf+9/FhotQEToejAcLEZtItMru8D1MhQLn17c8cS2QX104X5D3 RuDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Jj183wCh; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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. [23.128.96.18]) by mx.google.com with ESMTP id bf17si2463212edb.76.2021.01.27.23.02.20; Wed, 27 Jan 2021 23:02:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Jj183wCh; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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 S231316AbhA1HBJ (ORCPT + 7 others); Thu, 28 Jan 2021 02:01:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231309AbhA1HBD (ORCPT ); Thu, 28 Jan 2021 02:01:03 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C4E6C061756 for ; Wed, 27 Jan 2021 23:00:22 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id r38so3656132pgk.13 for ; Wed, 27 Jan 2021 23:00:22 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=ahYJzfuIo0e0JMYan7FcQvKFG+Ou8KUaBl9Hz3G4Bjc=; b=Jj183wChBfgZwye6P7NOZdByRSO/k/ZcMKjILrw2i4XOkpzoKon5D4OOzkfQjWVvKC pQxQYIbfGCkW1AiNxOKp+rix65EBzSWrDHRURncr7pPc/6FjLavepL/8x/ApoFT50heP by5LU73od8m75JVLXVBbKv2Ic+SSZ0v+UEqSgYrCdugV+9Hu7wParFrjV6XrSKZsLFeE LfO5wKINZo1p9+Kj34vrs4RoIsq9MGAn5v8gV0gEuDDORvzatn/znGK+dqrP+a1Y3hBl TSvDBMhQEBKJUMFeNrvTAX42vnHchyaqKUixcIbAulsC/5bL1GSD4aDFQrGFReinPZSw 9toQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ahYJzfuIo0e0JMYan7FcQvKFG+Ou8KUaBl9Hz3G4Bjc=; b=gKARno2DEIqtsdmEYa0ht/Xmj5HrsqlThNRiovcOVM0IPs0RETDrcbsXmLBAUCsvL4 3kPb3n4/RZiX1TTjKq2SoIgB5UHBOdt6hBM+lMEAaYxbCljbEkEN0yk/8q1rLVq2yny+ 7GcCyOELwGDSGONIUh2Dhm8nc+C8FDGYLptBeRxkAzy/tiLgNykhId9oYcG/lrrBf8TG 1XlIMKJio/mErncm0ap1E4KGdK6R62N1ihrYK8bL1vtTsanEQams+2WEDzIp6z76xTls DqIVTeUzLpzfUYMEpJFxQTiH1FxRF7C4k2eARgrqMDSGKbWfjk98qXRnU4qkws2BUrBN zlqA== X-Gm-Message-State: AOAM532qb9q04QiwB0vl13Z/6/QK6A5FOzNI3luC5/RZacByxHEVlT8/ BYgZbMR+pYP8e9TeNhC3sX5ZmA== X-Received: by 2002:a62:8c85:0:b029:1bd:5441:6cb8 with SMTP id m127-20020a628c850000b02901bd54416cb8mr14580564pfd.29.1611817222050; Wed, 27 Jan 2021 23:00:22 -0800 (PST) Received: from localhost ([122.172.59.240]) by smtp.gmail.com with ESMTPSA id gd9sm3965466pjb.10.2021.01.27.23.00.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jan 2021 23:00:21 -0800 (PST) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Rafael Wysocki , Dmitry Osipenko , linux-kernel@vger.kernel.org Subject: [PATCH V2 2/3] opp: Defer acquiring the clk until OPPs are added Date: Thu, 28 Jan 2021 12:30:08 +0530 Message-Id: <0c9026f0f4934d1106758284fb1583a7a6758219.1611817096.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: <1b58a72fa4d6aadc9542a66f8150150534752d81.1611817096.git.viresh.kumar@linaro.org> References: <1b58a72fa4d6aadc9542a66f8150150534752d81.1611817096.git.viresh.kumar@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org We acquire the clk at the time the OPP table is allocated, though it works fine, it is not the best place to do so. One of the main reason being we may need to acquire it again from dev_pm_opp_set_clkname() if the platform wants another clock to be acquired instead. There is also requirement from some of the platforms where they do not want the OPP core to manage the clock at all. This patch hence defers acquiring the clk until the time we are certain about which clk we need to acquire and if we really need to acquire one. With this commit, the clk will get acquired either from dev_pm_opp_set_clkname() or while we initialize the OPPs within the table. Signed-off-by: Viresh Kumar --- V2: - Split the earlier patch into two - Instead of skipping the clk-acquiring in _allocate_opp_table() based on getclk flag, defer it until later and get it only if we need to. drivers/opp/core.c | 73 ++++++++++++++++++++++++++++------------------ drivers/opp/of.c | 8 ++--- drivers/opp/opp.h | 2 +- 3 files changed, 50 insertions(+), 33 deletions(-) -- 2.25.0.rc1.19.g042ed3e048af diff --git a/drivers/opp/core.c b/drivers/opp/core.c index bf7cdab0ba64..52f4a64926e6 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1158,21 +1158,11 @@ static struct opp_table *_allocate_opp_table(struct device *dev, int index) _of_init_opp_table(opp_table, dev, index); - /* Find clk for the device */ - opp_table->clk = clk_get(dev, NULL); - if (IS_ERR(opp_table->clk)) { - ret = PTR_ERR(opp_table->clk); - if (ret == -EPROBE_DEFER) - goto remove_opp_dev; - - dev_dbg(dev, "%s: Couldn't find clock: %d\n", __func__, ret); - } - /* Find interconnect path(s) for the device */ ret = dev_pm_opp_of_find_icc_paths(dev, opp_table); if (ret) { if (ret == -EPROBE_DEFER) - goto put_clk; + goto remove_opp_dev; dev_warn(dev, "%s: Error finding interconnect paths: %d\n", __func__, ret); @@ -1184,9 +1174,6 @@ static struct opp_table *_allocate_opp_table(struct device *dev, int index) return opp_table; -put_clk: - if (!IS_ERR(opp_table->clk)) - clk_put(opp_table->clk); remove_opp_dev: _remove_opp_dev(opp_dev, opp_table); err: @@ -1199,6 +1186,33 @@ void _get_opp_table_kref(struct opp_table *opp_table) kref_get(&opp_table->kref); } +static struct opp_table *_update_opp_table_clk(struct device *dev, + struct opp_table *opp_table, + bool getclk) +{ + /* + * Return early if we don't need to get clk or we have already tried it + * earlier. + */ + if (!getclk || IS_ERR(opp_table) || opp_table->clk) + return opp_table; + + /* Find clk for the device */ + opp_table->clk = clk_get(dev, NULL); + if (IS_ERR(opp_table->clk)) { + int ret = PTR_ERR(opp_table->clk); + + if (ret == -EPROBE_DEFER) { + dev_pm_opp_put_opp_table(opp_table); + return ERR_PTR(ret); + } + + dev_dbg(dev, "%s: Couldn't find clock: %d\n", __func__, ret); + } + + return opp_table; +} + /* * We need to make sure that the OPP table for a device doesn't get added twice, * if this routine gets called in parallel with the same device pointer. @@ -1214,7 +1228,8 @@ void _get_opp_table_kref(struct opp_table *opp_table) * uses the opp_tables_busy flag to indicate if another creator is in the middle * of adding an OPP table and others should wait for it to finish. */ -struct opp_table *_add_opp_table_indexed(struct device *dev, int index) +struct opp_table *_add_opp_table_indexed(struct device *dev, int index, + bool getclk) { struct opp_table *opp_table; @@ -1261,12 +1276,12 @@ struct opp_table *_add_opp_table_indexed(struct device *dev, int index) unlock: mutex_unlock(&opp_table_lock); - return opp_table; + return _update_opp_table_clk(dev, opp_table, getclk); } -static struct opp_table *_add_opp_table(struct device *dev) +static struct opp_table *_add_opp_table(struct device *dev, bool getclk) { - return _add_opp_table_indexed(dev, 0); + return _add_opp_table_indexed(dev, 0, getclk); } struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) @@ -1711,7 +1726,7 @@ struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, { struct opp_table *opp_table; - opp_table = _add_opp_table(dev); + opp_table = _add_opp_table(dev, false); if (IS_ERR(opp_table)) return opp_table; @@ -1773,7 +1788,7 @@ struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name) { struct opp_table *opp_table; - opp_table = _add_opp_table(dev); + opp_table = _add_opp_table(dev, false); if (IS_ERR(opp_table)) return opp_table; @@ -1869,7 +1884,7 @@ struct opp_table *dev_pm_opp_set_regulators(struct device *dev, struct regulator *reg; int ret, i; - opp_table = _add_opp_table(dev); + opp_table = _add_opp_table(dev, false); if (IS_ERR(opp_table)) return opp_table; @@ -1980,7 +1995,7 @@ struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name) struct opp_table *opp_table; int ret; - opp_table = _add_opp_table(dev); + opp_table = _add_opp_table(dev, false); if (IS_ERR(opp_table)) return opp_table; @@ -1990,9 +2005,11 @@ struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name) goto err; } - /* Already have default clk set, free it */ - if (!IS_ERR(opp_table->clk)) - clk_put(opp_table->clk); + /* clk shouldn't be initialized at this point */ + if (WARN_ON(opp_table->clk)) { + ret = -EBUSY; + goto err; + } /* Find clk for the device */ opp_table->clk = clk_get(dev, name); @@ -2051,7 +2068,7 @@ struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, if (!set_opp) return ERR_PTR(-EINVAL); - opp_table = _add_opp_table(dev); + opp_table = _add_opp_table(dev, false); if (IS_ERR(opp_table)) return opp_table; @@ -2138,7 +2155,7 @@ struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, int index = 0, ret = -EINVAL; const char **name = names; - opp_table = _add_opp_table(dev); + opp_table = _add_opp_table(dev, false); if (IS_ERR(opp_table)) return opp_table; @@ -2306,7 +2323,7 @@ int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt) struct opp_table *opp_table; int ret; - opp_table = _add_opp_table(dev); + opp_table = _add_opp_table(dev, true); if (IS_ERR(opp_table)) return PTR_ERR(opp_table); diff --git a/drivers/opp/of.c b/drivers/opp/of.c index c6856dcf4c34..d4b51b2e384f 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -956,7 +956,7 @@ static int _of_add_opp_table_v1(struct device *dev, struct opp_table *opp_table) return ret; } -static int _of_add_table_indexed(struct device *dev, int index) +static int _of_add_table_indexed(struct device *dev, int index, bool getclk) { struct opp_table *opp_table; int ret, count; @@ -972,7 +972,7 @@ static int _of_add_table_indexed(struct device *dev, int index) index = 0; } - opp_table = _add_opp_table_indexed(dev, index); + opp_table = _add_opp_table_indexed(dev, index, getclk); if (IS_ERR(opp_table)) return PTR_ERR(opp_table); @@ -1010,7 +1010,7 @@ static int _of_add_table_indexed(struct device *dev, int index) */ int dev_pm_opp_of_add_table(struct device *dev) { - return _of_add_table_indexed(dev, 0); + return _of_add_table_indexed(dev, 0, true); } EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table); @@ -1026,7 +1026,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table); */ int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) { - return _of_add_table_indexed(dev, index); + return _of_add_table_indexed(dev, index, true); } EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_indexed); diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index ee2593afae0c..6e83855ade1f 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -223,7 +223,7 @@ int _opp_compare_key(struct dev_pm_opp *opp1, struct dev_pm_opp *opp2); int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table, bool rate_not_available); int _opp_add_v1(struct opp_table *opp_table, struct device *dev, unsigned long freq, long u_volt, bool dynamic); void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, int last_cpu); -struct opp_table *_add_opp_table_indexed(struct device *dev, int index); +struct opp_table *_add_opp_table_indexed(struct device *dev, int index, bool getclk); void _put_opp_list_kref(struct opp_table *opp_table); #ifdef CONFIG_OF From patchwork Thu Jan 28 07:00:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 372526 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp961746jam; Wed, 27 Jan 2021 23:02:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJzYQ1ZqSo4oVGpHS8x/BBg2Exsa0ISr9sEwAtVgANMI/q5QLz6RndIIwE2/mBHAoXmr/0Xd X-Received: by 2002:a17:906:6407:: with SMTP id d7mr8308651ejm.133.1611817345297; Wed, 27 Jan 2021 23:02:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611817345; cv=none; d=google.com; s=arc-20160816; b=jPinLQ/D/vEwpxTjzoepW46y/kBm/uC26YFKICX/I82wzJyiI15HVcTcAkkr8ELHJh tvUONA4/rFgcoKzAGOWRFaWza0oYH/UPx70cZ+0IF0VaKseUScN9sQbyAv80hd/KxXha 43wBvCnNm7yHHp5U5YnFY95B3AJ24Jqvx6LL8LsYr8geXbL8XBFsxIdxcPEQ8xMEPzeJ hYI3jLXBUASTVnnFZsuk7FCsKu4NFgyoI5fGWtDrQfo42P0gVMPWCR5fqfLDe11fkl2c nfZg+re5b/ynI0IAofdtjzQDHGmjy+0gTvYTKN7OHpOsWdD6OZaWUw2WyIzyNAPwEOyq W1jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7qDHxv287So/jBOR+Ptqf3OuXX9lBc2qUnXBXUEn81k=; b=PYjf59QXgSPL30RMUcNAmOuZ0dFjOQAm2S9VRWQHsupvFrwDcRrirXNCkcybbKP8yP hIn281QIyBEmGwqTF6Jsxrpnj8bfwfZ3T0X3cRZ98qwpv1ERQe/YiLvZmp6vHVHYiEYD Wk2jWcuNNWibkgdYIWmcqMunzCSlnL5Oi043Yh3+6vKkxNZ+mJx1YgH2rZ0gcrZwejyI zaq60MTujzryOkPsMSqSRqBsg4XNwP/icve23jYr1U2w0ti4LZGlwzbi5Y4hRPDCJ7g+ PQ1wwofs04RHH8sAN+DLhKDFeW9JUk2zjShg/+MIdtqje2aEhYE2HwFd8g+w23t93Qu5 VRKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yVKAEirq; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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. [23.128.96.18]) by mx.google.com with ESMTP id bf17si2463212edb.76.2021.01.27.23.02.25; Wed, 27 Jan 2021 23:02:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yVKAEirq; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-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 S231310AbhA1HBP (ORCPT + 7 others); Thu, 28 Jan 2021 02:01:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231314AbhA1HBG (ORCPT ); Thu, 28 Jan 2021 02:01:06 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E0EDC0613D6 for ; Wed, 27 Jan 2021 23:00:25 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id u15so2823312plf.1 for ; Wed, 27 Jan 2021 23:00:25 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=7qDHxv287So/jBOR+Ptqf3OuXX9lBc2qUnXBXUEn81k=; b=yVKAEirqsQAkNwNAY19C20Fw2OP4V8qKO0dJ2PY9EmdjWpFZ3qmIbbWvVJwJVuPvxV ZvvM2v/xE5C9KFSqCS06hLDs2zEuFEbJtbxv8UxbmGmyxFcEwsRrwVpZwCLXnyy6v0sG hlfMZHEMtrBuGZUhvAspBc6nsjghqypSjIbv+OqFRQfcfKECtRq5mapOSPi3qov+c+AA c4GY8Rtw1bnLL3UjGiyI+UsBzzO3Yyp8XXYa7iCDWd8cRFqeMqpzqwu0TwjKHoi0tGnP Ok2ZfGhsiMB6oEGvsENXoT2n2DDtXx5Z0op4JZywtauvPDpfWrYFkt30U8qhVudyeqZl bvHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7qDHxv287So/jBOR+Ptqf3OuXX9lBc2qUnXBXUEn81k=; b=Sqy2fsbXOf7e27dAP3dyzqBQTjZqOQKgtZj5wdNAYhbXJSKSf3irD9uUiKjAimfh87 e1niJuBSZKjPck2p351P+l2rQb1fbSlb66GpmCt4jG7M4B77oYShA/qTetsYT503K3ox sjOD8YP1TU/RsmE3D76urplHGeXtoo/a0WeAC/agph1AR5PeA7XeALrVbwbaZdfJk7H+ G48zGlKtUbHob0NbizZmxfqQsDb77cRromxbEvgqxQ4SU2kHz6Tzn9JVX/hAFtLMRTX2 jkkRI0wHUxPILYoIvQy9oIyD2eNAim+xMALxoZ7GNgOu972fQf0z89F21SPedsnqWP9w t4mQ== X-Gm-Message-State: AOAM53292JnWyfdOPtjJUd5sOGHDE4hfdAWmqZGP4MM62fjD1fW9JD0u j+J+06PpzTst3SUGosf4v2k7VA== X-Received: by 2002:a17:90b:350:: with SMTP id fh16mr9904813pjb.232.1611817225183; Wed, 27 Jan 2021 23:00:25 -0800 (PST) Received: from localhost ([122.172.59.240]) by smtp.gmail.com with ESMTPSA id x1sm4709767pgj.37.2021.01.27.23.00.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jan 2021 23:00:24 -0800 (PST) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Dmitry Osipenko , linux-kernel@vger.kernel.org Subject: [PATCH V2 3/3] opp: Add dev_pm_opp_of_add_table_noclk() Date: Thu, 28 Jan 2021 12:30:09 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af In-Reply-To: <1b58a72fa4d6aadc9542a66f8150150534752d81.1611817096.git.viresh.kumar@linaro.org> References: <1b58a72fa4d6aadc9542a66f8150150534752d81.1611817096.git.viresh.kumar@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org A few drivers have device's clk but they don't want the OPP core to handle that. Add a new helper for them, dev_pm_opp_of_add_table_noclk(). Signed-off-by: Viresh Kumar --- V2: - Split this into a separate patch. drivers/opp/of.c | 18 ++++++++++++++++++ include/linux/pm_opp.h | 6 ++++++ 2 files changed, 24 insertions(+) -- 2.25.0.rc1.19.g042ed3e048af Tested-by: Dmitry Osipenko diff --git a/drivers/opp/of.c b/drivers/opp/of.c index d4b51b2e384f..a905497c75f8 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -1030,6 +1030,24 @@ int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) } EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_indexed); +/** + * dev_pm_opp_of_add_table_noclk() - Initialize indexed opp table from device + * tree without getting clk for device. + * @dev: device pointer used to lookup OPP table. + * @index: Index number. + * + * Register the initial OPP table with the OPP library for given device only + * using the "operating-points-v2" property. Do not try to get the clk for the + * device. + * + * Return: Refer to dev_pm_opp_of_add_table() for return values. + */ +int dev_pm_opp_of_add_table_noclk(struct device *dev, int index) +{ + return _of_add_table_indexed(dev, index, false); +} +EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_noclk); + /* CPU device specific helpers */ /** diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 979b208bc4a8..158158620dde 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -395,6 +395,7 @@ static inline int dev_pm_opp_sync_regulators(struct device *dev) #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF) int dev_pm_opp_of_add_table(struct device *dev); int dev_pm_opp_of_add_table_indexed(struct device *dev, int index); +int dev_pm_opp_of_add_table_noclk(struct device *dev, int index); void dev_pm_opp_of_remove_table(struct device *dev); int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask); void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask); @@ -419,6 +420,11 @@ static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) return -ENOTSUPP; } +static inline int dev_pm_opp_of_add_table_noclk(struct device *dev, int index) +{ + return -ENOTSUPP; +} + static inline void dev_pm_opp_of_remove_table(struct device *dev) { }