From nobody Tue Apr 28 07:43:08 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E8BEC43334 for ; Fri, 3 Jun 2022 06:20:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241383AbiFCGUk (ORCPT ); Fri, 3 Jun 2022 02:20:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241381AbiFCGUb (ORCPT ); Fri, 3 Jun 2022 02:20:31 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 705BE31934 for ; Thu, 2 Jun 2022 23:20:29 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id p8so6502119pfh.8 for ; Thu, 02 Jun 2022 23:20:29 -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 :mime-version:content-transfer-encoding; bh=FtqSGSpcTYMhqEhiOK8deMmsDpT+y77WgcKMAx0xXi0=; b=x561OUt53M0UXGNsOFsZ+zaKCUzTGqTkew0UeDthOgHX3JQ4WVtTCji+ahD8BPJRso 7k39vcNQsWRwp3SCRX1nLP+zQvs4ymDVI0pJz+sqIaSotC+vJFJf9JWo6XbokVZoeW1q NvcCSgVRTH9krggLTZ/XvBABxZnWGrUxphO6kOj1Sl78xovk+Xfd7U/7QUCLYfvdFXMq U8TvBcc+5WSM8WTuWZ5iN9Z+H+evmAqJQ4ihAinRyb2xTpXa7Tkc7xJlavZ+jEskurs3 fPbvotzmPQXfk/cmqpzOJk2KfDO0arubZRS4C2jHFjUTdO4gcspkn99IxWNDVW/EThDs 5MIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FtqSGSpcTYMhqEhiOK8deMmsDpT+y77WgcKMAx0xXi0=; b=Zdiqp1XA8cog/0A3Bq2NARhyoHbcINv2sP/bwQioDIGtN7dEYErPExVUGuzcA7l3bf LI2jbxSMYeHN5jdKjFQPXhDCUMkBzuleTdCXXy3f9BLO0kvVWRQAI3g1sxifSOyNPoaA zG1yCjnIwJ53q5837qBjQ77q1yXGXcp2Gp/2ofxlGa7OOuRjXyrlMDzrmYhFkBWYjaST oUu4CAmx5CejzULMUo2oVJsb0z8XtehPtdt1E61BWT8mTtFlH77WdCFzpvzG3KJ17Ks0 E5mdaOznDDlYjQyxwH2xzrMX+tiSg0Sy6UFXEtK09KM08wxxaEhN9uJR+Zm/d4dkQnFj lV1g== X-Gm-Message-State: AOAM530WxYfwVRfU6YWLZ8kfu9RSS5CEkWfy2ByXcVchD+8ZJWatK5qg Ft/A8MRYUaK1+LaMzDUuCCOGrXSjtNqRTw== X-Google-Smtp-Source: ABdhPJxXOUS7EM/9384o4OYGzgHKDDVyzIFQnrK0vG1J1No1ZfoxjwGOqMi3WjHSf8PDzrED76RTRQ== X-Received: by 2002:a63:85c8:0:b0:3fd:1851:3d67 with SMTP id u191-20020a6385c8000000b003fd18513d67mr2440586pgd.520.1654237227929; Thu, 02 Jun 2022 23:20:27 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id d19-20020a17090ac25300b001cd4989feebsm6815158pjx.55.2022.06.02.23.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 23:20:27 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Krzysztof Kozlowski , linux-kernel@vger.kernel.org Subject: [PATCH 1/5] OPP: Remove dev_pm_opp_find_freq_ceil_by_volt() Date: Fri, 3 Jun 2022 11:50:15 +0530 Message-Id: <7b1d7a692f91e52da49b93f280ccba7014c139ba.1654235445.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This was added few years back, but the code that was supposed to use it never got merged. Remove the unused helper. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 54 ------------------------------------------ include/linux/pm_opp.h | 8 ------- 2 files changed, 62 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 554a043bc225..1ee218dcb0b9 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -600,60 +600,6 @@ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct d= evice *dev, } EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); =20 -/** - * dev_pm_opp_find_freq_ceil_by_volt() - Find OPP with highest frequency f= or - * target voltage. - * @dev: Device for which we do this operation. - * @u_volt: Target voltage. - * - * Search for OPP with highest (ceil) frequency and has voltage <=3D u_vol= t. - * - * Return: matching *opp, else returns ERR_PTR in case of error which shou= ld be - * handled using IS_ERR. - * - * Error return values can be: - * EINVAL: bad parameters - * - * The callers are required to call dev_pm_opp_put() for the returned OPP = after - * use. - */ -struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev, - unsigned long u_volt) -{ - struct opp_table *opp_table; - struct dev_pm_opp *temp_opp, *opp =3D ERR_PTR(-ERANGE); - - if (!dev || !u_volt) { - dev_err(dev, "%s: Invalid argument volt=3D%lu\n", __func__, - u_volt); - return ERR_PTR(-EINVAL); - } - - opp_table =3D _find_opp_table(dev); - if (IS_ERR(opp_table)) - return ERR_CAST(opp_table); - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->available) { - if (temp_opp->supplies[0].u_volt > u_volt) - break; - opp =3D temp_opp; - } - } - - /* Increment the reference count of OPP */ - if (!IS_ERR(opp)) - dev_pm_opp_get(opp); - - mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); - - return opp; -} -EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil_by_volt); - /** * dev_pm_opp_find_level_exact() - search for an exact level * @dev: device for which we do this operation diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index c6d8f01ef9fd..fde202b1f5a7 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -117,8 +117,6 @@ struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct de= vice *dev, bool available); struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, unsigned long *freq); -struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev, - unsigned long u_volt); =20 struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, unsigned int level); @@ -264,12 +262,6 @@ static inline struct dev_pm_opp *dev_pm_opp_find_freq_= floor(struct device *dev, return ERR_PTR(-EOPNOTSUPP); } =20 -static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct = device *dev, - unsigned long u_volt) -{ - return ERR_PTR(-EOPNOTSUPP); -} - static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *= dev, unsigned long *freq) { --=20 2.31.1.272.g89b43f80a514 From nobody Tue Apr 28 07:43:08 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7ABEAC433EF for ; Fri, 3 Jun 2022 06:20:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241430AbiFCGUo (ORCPT ); Fri, 3 Jun 2022 02:20:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241392AbiFCGUh (ORCPT ); Fri, 3 Jun 2022 02:20:37 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1D4231DF4 for ; Thu, 2 Jun 2022 23:20:31 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id j6so6471000pfe.13 for ; Thu, 02 Jun 2022 23:20:31 -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 :mime-version:content-transfer-encoding; bh=h1P/A46rz0jqr+k+LHINMkdY2BqpjbSfON2jDhuttCk=; b=bRZbRb0c6vbM3h5BD8ZwiJVDiaraTaM+flEivzgjZibK0703ajhsQiA8SeXBzTeQ1P 46URkWniAu7UOdd0g5z18mB6RKn8Pl+vNRONvHyOQecR9ML6/X/pPE6fwFrRKLJo0oa+ C2IgTYWwxQKmoD4u35TwTBCoFjh4cFWtJ3rmBoUmGqWBJK813JfzuUer5YoTeWP827EZ 9Vs/UuOC9ESJ14R1Ej/3XMqgIRA9WFWuL3ND0z7t3SOsHkCGkqfwSrYrSkxA/XS60QIb l/0Ehy1R919k5a8HA37sEv6333fwbsejHKjQZNgARebERYHCUvytBq8iKFxxQM0rFRVE 4sUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=h1P/A46rz0jqr+k+LHINMkdY2BqpjbSfON2jDhuttCk=; b=qdqzh+pUG1RXVmgJaRfrBI6sPN+sS7gtutpwFGsu6urQU/vMQgHDCeGIPH6HTcefJJ SdqD1JKZRVvSlqvu056UlUQRY2p8zQXYlVKebZloeZghTd0nyrgqxJa9U0EOF2dbqzHn stlQfqd3BE5p41vYHTqTbtZmbeC4NW/jFV0uK99GXw/GqvSverwcaTzNi+zrq74OnDFD O6S/plG+lGRg1xb2Lieo+i4ejmhZmqfiCKtTPIHe9HVNib5b9YOdcaEfGMljmjmKvpRj ZEsgk6qlFNSiCL4IwAKjtxUkGAkdRxr8VtjiyqA8V9pET8XvlOZAYDe4aFirRqJrwE6t pKrw== X-Gm-Message-State: AOAM5337sXePFk4PhODAhUysGxJLVkeX1NkEwKrncbxc7btwtOVCsBm2 2HOgIUZE1LdaGaWYd9/7jWbqRA== X-Google-Smtp-Source: ABdhPJxY4oWi3mOzIZS/bc0MEnpzrXKxSgYmAb7SDcvCmYxl2hJuyDWFqwYtZZ4Gx+IVApZ9JlK5RQ== X-Received: by 2002:a05:6a00:10cc:b0:505:ada6:e03e with SMTP id d12-20020a056a0010cc00b00505ada6e03emr8905928pfu.45.1654237231271; Thu, 02 Jun 2022 23:20:31 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id y20-20020a170902d65400b00163cc9d6a04sm4606486plh.299.2022.06.02.23.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 23:20:30 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Krzysztof Kozlowski , linux-kernel@vger.kernel.org Subject: [PATCH 2/5] OPP: Add generic key finding helpers Date: Fri, 3 Jun 2022 11:50:16 +0530 Message-Id: <015602dc3313be081ce2b5b2057361dab95d55b9.1654235445.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" There are three type of helpers, to find exact, ceil, and floor values, replicated for multiple key types, freq, level, bw. And all of these helpers share a lot of boilerplate code. Add generic key finding helpers to reduce code redundancy. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 132 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 1ee218dcb0b9..7ef6eafc7946 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -420,6 +420,138 @@ int dev_pm_opp_get_opp_count(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_count); =20 +/* Helpers to read keys */ +static unsigned long _read_freq(struct dev_pm_opp *opp, int index) +{ + return opp->rate; +} + +static unsigned long _read_level(struct dev_pm_opp *opp, int index) +{ + return opp->level; +} + +static unsigned long _read_bw(struct dev_pm_opp *opp, int index) +{ + return opp->bandwidth[index].peak; +} + +/* Generic comparison helpers */ +static bool _compare_exact(struct dev_pm_opp **opp, struct dev_pm_opp *tem= p_opp, + unsigned long opp_key, unsigned long key) +{ + if (opp_key =3D=3D key) { + *opp =3D temp_opp; + return true; + } + + return false; +} + +static bool _compare_ceil(struct dev_pm_opp **opp, struct dev_pm_opp *temp= _opp, + unsigned long opp_key, unsigned long key) +{ + if (opp_key >=3D key) { + *opp =3D temp_opp; + return true; + } + + return false; +} + +static bool _compare_floor(struct dev_pm_opp **opp, struct dev_pm_opp *tem= p_opp, + unsigned long opp_key, unsigned long key) +{ + if (opp_key > key) + return true; + + *opp =3D temp_opp; + return false; +} + +/* Generic key finding helpers */ +static struct dev_pm_opp * +_opp_table_find_key(struct opp_table *opp_table, unsigned long *key, int i= ndex, bool available, + unsigned long (*read)(struct dev_pm_opp *opp, int index), + bool (*compare)(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, + unsigned long opp_key, unsigned long key)) +{ + struct dev_pm_opp *temp_opp, *opp =3D ERR_PTR(-ERANGE); + + mutex_lock(&opp_table->lock); + + list_for_each_entry(temp_opp, &opp_table->opp_list, node) { + if (temp_opp->available =3D=3D available) { + if (compare(&opp, temp_opp, read(temp_opp, index), *key)) + break; + } + } + + /* Increment the reference count of OPP */ + if (!IS_ERR(opp)) { + *key =3D read(opp, index); + dev_pm_opp_get(opp); + } + + mutex_unlock(&opp_table->lock); + + return opp; +} + +static struct dev_pm_opp * +_find_key(struct device *dev, unsigned long *key, int index, bool availabl= e, + unsigned long (*read)(struct dev_pm_opp *opp, int index), + bool (*compare)(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, + unsigned long opp_key, unsigned long key)) +{ + struct opp_table *opp_table; + struct dev_pm_opp *opp; + + opp_table =3D _find_opp_table(dev); + if (IS_ERR(opp_table)) { + dev_err(dev, "%s: OPP table not found (%ld)\n", __func__, PTR_ERR(opp_ta= ble)); + return ERR_CAST(opp_table); + } + + opp =3D _opp_table_find_key(opp_table, key, index, available, read, compa= re); + + dev_pm_opp_put_opp_table(opp_table); + + return opp; +} + +static struct dev_pm_opp * +_find_key_exact(struct device *dev, unsigned long key, int index, bool ava= ilable, + unsigned long (*read)(struct dev_pm_opp *opp, int index)) +{ + /* + * The value of key will be updated here, but will be ignored as the + * caller doesn't need it. + */ + return _find_key(dev, &key, index, available, read, _compare_exact); +} + +static struct dev_pm_opp * +_opp_table_find_key_ceil(struct opp_table *opp_table, unsigned long *key, = int index, bool available, + unsigned long (*read)(struct dev_pm_opp *opp, int index)) +{ + return _opp_table_find_key(opp_table, key, index, available, read, _compa= re_ceil); +} + +static struct dev_pm_opp * +_find_key_ceil(struct device *dev, unsigned long *key, int index, bool ava= ilable, + unsigned long (*read)(struct dev_pm_opp *opp, int index)) +{ + return _find_key(dev, key, index, available, read, _compare_ceil); +} + +static struct dev_pm_opp * +_find_key_floor(struct device *dev, unsigned long *key, int index, bool av= ailable, + unsigned long (*read)(struct dev_pm_opp *opp, int index)) +{ + return _find_key(dev, key, index, available, read, _compare_floor); +} + /** * dev_pm_opp_find_freq_exact() - search for an exact frequency * @dev: device for which we do this operation --=20 2.31.1.272.g89b43f80a514 From nobody Tue Apr 28 07:43:08 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4092C433EF for ; Fri, 3 Jun 2022 06:20:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241441AbiFCGUq (ORCPT ); Fri, 3 Jun 2022 02:20:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241395AbiFCGUh (ORCPT ); Fri, 3 Jun 2022 02:20:37 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D75B433355 for ; Thu, 2 Jun 2022 23:20:34 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id n8so6215223plh.1 for ; Thu, 02 Jun 2022 23:20:34 -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 :mime-version:content-transfer-encoding; bh=AJWbZrhYBBK/nZwEp8oEDzNVeqkUQnXH1sic0IKz15o=; b=FYJXrijbSyRV9DxoEDjyD5K0VwHrFPs2Rxn229GB700FpcNUBGlnxk/4+4TUtNVXTs EFykN0qpLNv4lF0FHxHrVyKOCkp4oe4UbnbRR9/X0CMmPhS4DDKsGO+dpFn1ZG3o9PS5 1uDP0ePVuxajD0juj1+hWAR+JjeUm25WCnRdEr83g5g+kOG40UKKZ94YRoTcaUucAbBU ewE+Fvz4B6TpBOq8OwgaGUcTFgA6Cvgt+xfZ9wy7zhMztaGUUV2awuWnykBWGFJ13HOt qSkUtbilU1K7oM4WKjgwp2ZX8Y00mqlg9VqSmBTzJo7HBkul5J5NYTHCvALlNns6ci7l pjxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AJWbZrhYBBK/nZwEp8oEDzNVeqkUQnXH1sic0IKz15o=; b=2nIoTjPLTWNFMgLsnuiq5/8qk4ZAqEfhjCTHShE0abglF6J5vbi/V5oTjYQXdy/4Hq Wkg3fKp/Dqr+jIg3gDTmZ/tFUzprS6xDmUU4fkpWbIxlZBjznT81ES+GEHNlKXVKrOzV AJrzxADD1T/CxpECujg7BqetVS/DKaaCFCc4ggUZc3s130NBBRSZQw0jffKWZ2VP3jzO MI8dKj5nRZYdhOFtMOE4PwB3Yphq1ZDJky9U3Lsdl0Zoqm9lw2n/fCirXC2y90iCfBrd 3p/V2oW2tei6hRLIgpqfJGe9HyTJb6iP3IbKy6PHXgQgF4Ve+Q9wB7Jcy21FohzXCVzW 0LXA== X-Gm-Message-State: AOAM530BGnwUKjC9/64ECT4IrxgHGZAALkMrq+ELV9U2fc8H/iosWjCt g6PZnMMQpqIt/y3YanlPdr6dJg== X-Google-Smtp-Source: ABdhPJx6Fes6DwkCQHCVRV+H/LydnWY82HwtV8Rol5UHgNxnFTNnHK9lxTrRfSlmwBiUM6XO+kBz6g== X-Received: by 2002:a17:902:db0a:b0:167:466e:b72c with SMTP id m10-20020a170902db0a00b00167466eb72cmr2387021plx.172.1654237234341; Thu, 02 Jun 2022 23:20:34 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id r14-20020a63ec4e000000b003fb0354c43asm4387425pgj.32.2022.06.02.23.20.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 23:20:33 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Krzysztof Kozlowski , linux-kernel@vger.kernel.org Subject: [PATCH 3/5] OPP: Use generic key finding helpers for freq key Date: Fri, 3 Jun 2022 11:50:17 +0530 Message-Id: <7bbf461f918b62867305f7ede05ee6691246f3e9.1654235445.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use the recently added generic key findings helpers to find frequency key values. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 113 ++++----------------------------------------- 1 file changed, 8 insertions(+), 105 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 7ef6eafc7946..2e6cb2abf0b9 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -575,62 +575,16 @@ _find_key_floor(struct device *dev, unsigned long *ke= y, int index, bool availabl * The callers are required to call dev_pm_opp_put() for the returned OPP = after * use. */ -struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, - unsigned long freq, +struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, unsigned= long freq, bool available) { - struct opp_table *opp_table; - struct dev_pm_opp *temp_opp, *opp =3D ERR_PTR(-ERANGE); - - opp_table =3D _find_opp_table(dev); - if (IS_ERR(opp_table)) { - int r =3D PTR_ERR(opp_table); - - dev_err(dev, "%s: OPP table not found (%d)\n", __func__, r); - return ERR_PTR(r); - } - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->available =3D=3D available && - temp_opp->rate =3D=3D freq) { - opp =3D temp_opp; - - /* Increment the reference count of OPP */ - dev_pm_opp_get(opp); - break; - } - } - - mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); - - return opp; + return _find_key_exact(dev, freq, 0, available, _read_freq); } EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_exact); =20 -static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_t= able, - unsigned long *freq) +static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_t= able, unsigned long *freq) { - struct dev_pm_opp *temp_opp, *opp =3D ERR_PTR(-ERANGE); - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->available && temp_opp->rate >=3D *freq) { - opp =3D temp_opp; - *freq =3D opp->rate; - - /* Increment the reference count of OPP */ - dev_pm_opp_get(opp); - break; - } - } - - mutex_unlock(&opp_table->lock); - - return opp; + return _opp_table_find_key_ceil(opp_table, freq, 0, true, _read_freq); } =20 /** @@ -651,26 +605,9 @@ static noinline struct dev_pm_opp *_find_freq_ceil(str= uct opp_table *opp_table, * The callers are required to call dev_pm_opp_put() for the returned OPP = after * use. */ -struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, - unsigned long *freq) +struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, unsigned = long *freq) { - struct opp_table *opp_table; - struct dev_pm_opp *opp; - - if (!dev || !freq) { - dev_err(dev, "%s: Invalid argument freq=3D%p\n", __func__, freq); - return ERR_PTR(-EINVAL); - } - - opp_table =3D _find_opp_table(dev); - if (IS_ERR(opp_table)) - return ERR_CAST(opp_table); - - opp =3D _find_freq_ceil(opp_table, freq); - - dev_pm_opp_put_opp_table(opp_table); - - return opp; + return _find_key_ceil(dev, freq, 0, true, _read_freq); } EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil); =20 @@ -692,43 +629,9 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil); * The callers are required to call dev_pm_opp_put() for the returned OPP = after * use. */ -struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, - unsigned long *freq) +struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, unsigned= long *freq) { - struct opp_table *opp_table; - struct dev_pm_opp *temp_opp, *opp =3D ERR_PTR(-ERANGE); - - if (!dev || !freq) { - dev_err(dev, "%s: Invalid argument freq=3D%p\n", __func__, freq); - return ERR_PTR(-EINVAL); - } - - opp_table =3D _find_opp_table(dev); - if (IS_ERR(opp_table)) - return ERR_CAST(opp_table); - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->available) { - /* go to the next node, before choosing prev */ - if (temp_opp->rate > *freq) - break; - else - opp =3D temp_opp; - } - } - - /* Increment the reference count of OPP */ - if (!IS_ERR(opp)) - dev_pm_opp_get(opp); - mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); - - if (!IS_ERR(opp)) - *freq =3D opp->rate; - - return opp; + return _find_key_floor(dev, freq, 0, true, _read_freq); } EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); =20 --=20 2.31.1.272.g89b43f80a514 From nobody Tue Apr 28 07:43:08 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20305C433EF for ; Fri, 3 Jun 2022 06:20:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241437AbiFCGUt (ORCPT ); Fri, 3 Jun 2022 02:20:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241398AbiFCGUj (ORCPT ); Fri, 3 Jun 2022 02:20:39 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D67D531DE6 for ; Thu, 2 Jun 2022 23:20:37 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id u18so6212788plb.3 for ; Thu, 02 Jun 2022 23:20:37 -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 :mime-version:content-transfer-encoding; bh=4vGD8xeygMuouGJmhsw5Y0o7g11kgBD47l9iHV0atlE=; b=PAIEVagjF87QEZSuJ46V1NbanKyWVzHu2P+0TaPHRFAhFD/E10fEZcstdDjH5aHwc6 kYXteNBdgV0t6hCyV9o1IWNvNeDQ2I3GL1ssgEnfy8XeQFNt0QwiEqFJ0dO06GqdsC0A WcavoNLbur3qNEUc1rlZ3GUBcu9xZiwLJoW4sXZpE7t28EUtZduSTYd8C8HZg/WNzrGj MiePq5i06UBmBWqxw8jqWEjn3bjsyIeA/1NmH+Xwk/g3CU63Hsw6oRpUFTW15Uh5XEDw twHqF6GuAhuZOkSWVKp+MdXXyhHJ0EvVV1cCFWnMO3BGHAcWLzSv5xGqJTDrYsNTrwet dijg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4vGD8xeygMuouGJmhsw5Y0o7g11kgBD47l9iHV0atlE=; b=skmCl7Sy5FD/x0J74QOnd/G9+n3ByslLVQcYoieK3+UXh2XLklBOU+E+02pDzimyy0 1cuDyC/Dx/ieYIRsASDQn3yZnD6lw6/IdZx5aVXuw0rx7uadpvWjXtBS3qw/EKy6Z/8b zw3UE+uh+qiNPDNGixxEQrj1t/B7EWwlNBaqzX/w6svh4vsmmEYqf6m5IYLpGU05tGok xzajgn/z1cRVceV2+VqE1igs9+TrY/oaxdIDlA70LM2QGCG7puppCos3/Tx12K1F4Lq/ MYq1g02gAY1C7QqY8i9cmxYdsnEm2KLTXdwv3/PbIMIyzqqOyK7E4b5tchitHoh0gGcX lN3Q== X-Gm-Message-State: AOAM532wM6Zv6H3pmXxTodGF66bh9Dn213yTvb158C9foNMNTTfsmfPL 5S14kqjamUI9pjFUPOE6vnNCVg== X-Google-Smtp-Source: ABdhPJx3v0WTCiUSqEVf4ES8VFLb1f6/DrsOqENUN5DKirn9hteNSryYlnTTzGPxvH8DKzLFQxTAiw== X-Received: by 2002:a17:902:cf06:b0:163:62cb:250e with SMTP id i6-20020a170902cf0600b0016362cb250emr8720003plg.171.1654237237301; Thu, 02 Jun 2022 23:20:37 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id fh6-20020a17090b034600b001cd4989fec6sm6837272pjb.18.2022.06.02.23.20.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 23:20:36 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Krzysztof Kozlowski , linux-kernel@vger.kernel.org Subject: [PATCH 4/5] OPP: Use generic key finding helpers for level key Date: Fri, 3 Jun 2022 11:50:18 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use the recently added generic key findings helpers to find level key values. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 60 +++------------------------------------------- 1 file changed, 3 insertions(+), 57 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 2e6cb2abf0b9..d8a91900d8a9 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -650,36 +650,9 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); * The callers are required to call dev_pm_opp_put() for the returned OPP = after * use. */ -struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, - unsigned int level) +struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, unsigne= d int level) { - struct opp_table *opp_table; - struct dev_pm_opp *temp_opp, *opp =3D ERR_PTR(-ERANGE); - - opp_table =3D _find_opp_table(dev); - if (IS_ERR(opp_table)) { - int r =3D PTR_ERR(opp_table); - - dev_err(dev, "%s: OPP table not found (%d)\n", __func__, r); - return ERR_PTR(r); - } - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->level =3D=3D level) { - opp =3D temp_opp; - - /* Increment the reference count of OPP */ - dev_pm_opp_get(opp); - break; - } - } - - mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); - - return opp; + return _find_key_exact(dev, level, 0, true, _read_level); } EXPORT_SYMBOL_GPL(dev_pm_opp_find_level_exact); =20 @@ -701,34 +674,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_level_exact); struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev, unsigned int *level) { - struct opp_table *opp_table; - struct dev_pm_opp *temp_opp, *opp =3D ERR_PTR(-ERANGE); - - opp_table =3D _find_opp_table(dev); - if (IS_ERR(opp_table)) { - int r =3D PTR_ERR(opp_table); - - dev_err(dev, "%s: OPP table not found (%d)\n", __func__, r); - return ERR_PTR(r); - } - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->available && temp_opp->level >=3D *level) { - opp =3D temp_opp; - *level =3D opp->level; - - /* Increment the reference count of OPP */ - dev_pm_opp_get(opp); - break; - } - } - - mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); - - return opp; + return _find_key_ceil(dev, (unsigned long *)level, 0, true, _read_level); } EXPORT_SYMBOL_GPL(dev_pm_opp_find_level_ceil); =20 --=20 2.31.1.272.g89b43f80a514 From nobody Tue Apr 28 07:43:08 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04C90C433EF for ; Fri, 3 Jun 2022 06:20:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241476AbiFCGUz (ORCPT ); Fri, 3 Jun 2022 02:20:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241434AbiFCGUo (ORCPT ); Fri, 3 Jun 2022 02:20:44 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8A2837038 for ; Thu, 2 Jun 2022 23:20:40 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id i185so6520962pge.4 for ; Thu, 02 Jun 2022 23:20:40 -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 :mime-version:content-transfer-encoding; bh=gbNLNoNUtLpmvXGtkruf34xAYHi/j4E55WSdSx4bUmU=; b=JYxSDO1g1tQSMHpPKKPMY2RVHLSYsZM4Akn7PtJlzCFV7ZBIWYNnG/MH4qSb/Z962J p/Rlz7u3eTr0pn258InQjm1G49vXSF5ZtywFATcuk86gmi89yiVoEU0P8uYAC0iMeu0+ 83L3xO5tQG/YrMiPjMNtnJjIATeKT2bggZ4aj31Agl0IPbkNBzopWEGddpxO2kk9AKUt brS6x5cvldkh9cfyMeWy+LEmF682U99ZcZLq2VP5/VRTfTjGsqTVxkBYDiAqAlSHPX4+ K/NahCHpDS62o7bQBnFqIBKNd6L4jrN+Vw7I9rGqy0ea7Q7Ki22JoEkiLKovFBdZfzVc DHKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gbNLNoNUtLpmvXGtkruf34xAYHi/j4E55WSdSx4bUmU=; b=jLFIDNzmZEPn61TXzv91dvKtr/TfQDL1h+T4OHlftid/Glk034UoQsMIc9mcseJMBS OxsbwDRlLs8JVyb9QltXOzNk8C3LC3PebaSSnJH8RVmosn/ZvCdh5qG9uvKxgIMKnY7e El/zIZGHM/nlRFa3Wy5SNhmcIwNd+rPYQmyXCL5MG+btnieKnX6sVtgNpSFv32po+HZb yUR7poaq1tPO+VjshZl4SFwkGNiwuA+Ue5ESsUpf1XNVC/6STGvfpYwohUBIb7mkjkSR lCMufArI9o6bYSZkh5aaEvjYPHu4uEooygfecJHOwK/trLaX0b59QSLNsl9IQ/KJ4FBD 5Mow== X-Gm-Message-State: AOAM531HMq725oRHR0a8Qr0EABPXi0PvjUdySvdRfT5/NbSoIpGSNYh8 /zjarP/R62Gb/fQyZpW/OKlWXA== X-Google-Smtp-Source: ABdhPJztO9aPd48ZSjjD4aY9lShRgqdRU7Zs47AgfKXEdv0GxvFhUwP8Z+mcxJuzKx4yAUM+L2AMrA== X-Received: by 2002:a63:305:0:b0:3fc:7f18:8d7 with SMTP id 5-20020a630305000000b003fc7f1808d7mr7469116pgd.186.1654237240030; Thu, 02 Jun 2022 23:20:40 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id a6-20020a170902710600b00163a6e1416dsm4575155pll.32.2022.06.02.23.20.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 23:20:39 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Krzysztof Kozlowski , linux-kernel@vger.kernel.org Subject: [PATCH 5/5] OPP: Use generic key finding helpers for bandwidth key Date: Fri, 3 Jun 2022 11:50:19 +0530 Message-Id: <07c76851ac311d704522aef1d8712550ef1ac7ca.1654235445.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use the recently added generic key findings helpers to find bandwidth key values. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 78 +++------------------------------------------- 1 file changed, 4 insertions(+), 74 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index d8a91900d8a9..f17e19872769 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -697,43 +697,9 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_level_ceil); * The callers are required to call dev_pm_opp_put() for the returned OPP = after * use. */ -struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev, - unsigned int *bw, int index) +struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev, unsigned in= t *bw, int index) { - struct opp_table *opp_table; - struct dev_pm_opp *temp_opp, *opp =3D ERR_PTR(-ERANGE); - - if (!dev || !bw) { - dev_err(dev, "%s: Invalid argument bw=3D%p\n", __func__, bw); - return ERR_PTR(-EINVAL); - } - - opp_table =3D _find_opp_table(dev); - if (IS_ERR(opp_table)) - return ERR_CAST(opp_table); - - if (index >=3D opp_table->path_count) - return ERR_PTR(-EINVAL); - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->available && temp_opp->bandwidth) { - if (temp_opp->bandwidth[index].peak >=3D *bw) { - opp =3D temp_opp; - *bw =3D opp->bandwidth[index].peak; - - /* Increment the reference count of OPP */ - dev_pm_opp_get(opp); - break; - } - } - } - - mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); - - return opp; + return _find_key_ceil(dev, (unsigned long *)bw, index, true, _read_bw); } EXPORT_SYMBOL_GPL(dev_pm_opp_find_bw_ceil); =20 @@ -756,45 +722,9 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_bw_ceil); * The callers are required to call dev_pm_opp_put() for the returned OPP = after * use. */ -struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev, - unsigned int *bw, int index) +struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev, unsigned i= nt *bw, int index) { - struct opp_table *opp_table; - struct dev_pm_opp *temp_opp, *opp =3D ERR_PTR(-ERANGE); - - if (!dev || !bw) { - dev_err(dev, "%s: Invalid argument bw=3D%p\n", __func__, bw); - return ERR_PTR(-EINVAL); - } - - opp_table =3D _find_opp_table(dev); - if (IS_ERR(opp_table)) - return ERR_CAST(opp_table); - - if (index >=3D opp_table->path_count) - return ERR_PTR(-EINVAL); - - mutex_lock(&opp_table->lock); - - list_for_each_entry(temp_opp, &opp_table->opp_list, node) { - if (temp_opp->available && temp_opp->bandwidth) { - /* go to the next node, before choosing prev */ - if (temp_opp->bandwidth[index].peak > *bw) - break; - opp =3D temp_opp; - } - } - - /* Increment the reference count of OPP */ - if (!IS_ERR(opp)) - dev_pm_opp_get(opp); - mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); - - if (!IS_ERR(opp)) - *bw =3D opp->bandwidth[index].peak; - - return opp; + return _find_key_floor(dev, (unsigned long *)bw, index, true, _read_bw); } EXPORT_SYMBOL_GPL(dev_pm_opp_find_bw_floor); =20 --=20 2.31.1.272.g89b43f80a514