Received: by 2002:a05:7412:bb8d:b0:d7:7d3a:4fe2 with SMTP id js13csp75742rdb; Mon, 14 Aug 2023 09:54:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHSCtq6sK11gkv6j3IfW/SMkS44qzynsj6mE4eDV+zS1mpyrLS4Tq1iULMCdH9m1hIIs7PY X-Received: by 2002:a05:6a20:4cb:b0:131:6fd:8f5a with SMTP id 11-20020a056a2004cb00b0013106fd8f5amr6674053pzd.32.1692032080640; Mon, 14 Aug 2023 09:54:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692032080; cv=none; d=google.com; s=arc-20160816; b=ZLXEx/89tO/AUwJPEOPnqu/DxI7Bfw2NdSatvymRMX2n2tLUr2Pv/8DBhQrQ0CQls9 72uavKWEZSf3FKrsSlXvAbBrtyT098ylYi/0ay06uCfZpL191IeT7peR4K/NoN01Jzy+ brwWXjTrubjS8y8ddbDoBOmMZrbTnLES2gtgI5HzuTXz0ho42b6gYp28ImNVVMsbzFx8 ca5dMSsz1lJatPHhdlqoyu5KoPHe1aLrtSX3dpJbZeqVB9ZbbM3PTwcvG+dJtbbujrpp iNRu80a1UT0oXLfvp0vjsXVmGuNdmlDG/01Epgf4lvbU/BRYB9Uf5nbeoEtvxyIQrlzt 2ntA== 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=l9FgIR5BO1ZA/xwnNK7HzsY7163eVVAl221xkKgdSQ4=; fh=zUAAL0oq2+kA0nMRT5WSj9jrme2MlEZTDW5RK2mes1s=; b=dmxSAd6dYOKWIz7NCS+vBsT1JV0GZYC/HjjJE96wevX4DHVL415iTfSwVOOFWGtK6/ Kh902M2ZMBi6yi67BwIYsL/xigLWTL1UbHr5QiUH5kj/GeNtqLxBnzEaj7Ah1hQiQBdH TV+lAjgM2ffZjnmnFk/eEHyNwP/LnhcGrpmX3qC5Hi2hpdbLFGMRIUDIFa0uHTRysIo4 XCtLsvA9bhpAQ1IqZuVE3IR3BKZNhacjuCokTM8Xq5PgOsZ4hsesUMesppu/pkV1LQXd dj8QCfyNESHTvRltDxoTJ3EoWALwWdOFG9TxNkll9BbVLoEKr1WPdU+WNvtuugQzCx+s s7cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=t0DrTBKA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e129-20020a636987000000b005303a26dbf8si8256724pgc.408.2023.08.14.09.54.27; Mon, 14 Aug 2023 09:54:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=t0DrTBKA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232776AbjHNQ35 (ORCPT + 99 others); Mon, 14 Aug 2023 12:29:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232511AbjHNQ3a (ORCPT ); Mon, 14 Aug 2023 12:29:30 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 448F810F2 for ; Mon, 14 Aug 2023 09:29:26 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fe4ad22eb0so44413685e9.3 for ; Mon, 14 Aug 2023 09:29:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692030565; x=1692635365; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l9FgIR5BO1ZA/xwnNK7HzsY7163eVVAl221xkKgdSQ4=; b=t0DrTBKAUnZsOhKTySRBhIZjBEyiCu6lrIZbKlxcEhX6zO1Ez+fk0jM/I6CoLWplDS ntt6v5+8AXCoamgE9CwhyNauIGGhB5vI+AUO6towiMb7WC/K62f7Tw69AyzUY5Mmu+ck 4TqxDvSRKcyTu1c3YonMVg/VVhb6f/FF6NQi54/GTMeuSXqikJpYaLrAix5rsPjDFP7a xxOebx1jx3FWvnIfSbh0Mbc5CNX2ZseiM0RbbtmOP7RTPhfCp8sX7ADwJmmZ02MvBins oexMWOyPM46Y7BI/3IaFBT5msykygWtnD7W2JiHoGS/xWY14wFfdMJETFskRv0N9Mtkk /97g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692030565; x=1692635365; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l9FgIR5BO1ZA/xwnNK7HzsY7163eVVAl221xkKgdSQ4=; b=HJO0mBbT6IaRYw964DxezttShY8HXls67LewA2UMAt7To2ieMUJZiMxkORtJaK4VjD LmPIb/S6Fej0ZbGBeJpIgPcJ+9/DU65/vAwYJW07hAAoOFmdYdHrgVV1qDaBSosEvoSI TA5u7ewMdFpvuA/YcbvJwx36YpgwVgzfasx7ChFfcGlVFKQreKKwJ+4I0WlsEfOiWFJW 20yLLs25cr43/uvq5j30vQY3IorKa3vMMkHiayUyBwxL82gvmgt5kUisQ1HulC4aTGpH JX7o6gibrXYoFtbvpzu/w3hnMFq4SYb/qLcvtEJ8e/eY4wZD9f1eOxSPNy+7xSWfxCoF ocRA== X-Gm-Message-State: AOJu0Yzd0uZ86cWFzj24VvnAfiUwmakfhnKWngG11Dd4+eq3OM53ZOib SOamBICxkCznqOQ2TD0UyjpEzg== X-Received: by 2002:a05:600c:82c5:b0:3fe:90f:8496 with SMTP id eo5-20020a05600c82c500b003fe090f8496mr7756053wmb.1.1692030564860; Mon, 14 Aug 2023 09:29:24 -0700 (PDT) Received: from sagittarius-a.chello.ie (188-141-3-169.dynamic.upc.ie. [188.141.3.169]) by smtp.gmail.com with ESMTPSA id l14-20020a1c790e000000b003fc16ee2864sm14743475wme.48.2023.08.14.09.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 09:29:24 -0700 (PDT) From: Bryan O'Donoghue To: rfoss@kernel.org, todor.too@gmail.com, bryan.odonoghue@linaro.org, agross@kernel.org, andersson@kernel.org, konrad.dybcio@linaro.org, mchehab@kernel.org, hverkuil-cisco@xs4all.nl, laurent.pinchart@ideasonboard.com, sakari.ailus@linux.intel.com, andrey.konovalov@linaro.org Cc: linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 12/14] media: qcom: camss: Functionally decompose CSIPHY clock lookups Date: Mon, 14 Aug 2023 17:29:05 +0100 Message-ID: <20230814162907.3878421-13-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230814162907.3878421-1-bryan.odonoghue@linaro.org> References: <20230814162907.3878421-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The csiphyX_timer and csiX_phy values need not be hard-coded. We can functionally decompose the string matching inside of a loop. Static string values are brittle, difficult to extend and not required anyway since the camss->res->csiphy_num value informs us of the number of CSIPHYs and hence the set of potential clocks for a given CSIPHY. In simple terms if we have five CSIPHYs we can have no more and no less than five csiphy_timer clocks. Similarly csi_phy core clocks have a 1:1 relationship with the PHY they clock. Signed-off-by: Bryan O'Donoghue --- .../media/platform/qcom/camss/camss-csiphy.c | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c b/drivers/media/platform/qcom/camss/camss-csiphy.c index 0e8c2a59ea241..baf78c525fbfc 100644 --- a/drivers/media/platform/qcom/camss/camss-csiphy.c +++ b/drivers/media/platform/qcom/camss/camss-csiphy.c @@ -536,6 +536,15 @@ static int csiphy_init_formats(struct v4l2_subdev *sd, return csiphy_set_format(sd, fh ? fh->state : NULL, &format); } +static bool csiphy_match_clock_name(const char *clock_name, const char *format, + int index) +{ + char name[CAMSS_RES_MAX]; + + snprintf(name, sizeof(name), format, index); + return !strcmp(clock_name, name); +} + /* * msm_csiphy_subdev_init - Initialize CSIPHY device structure and resources * @csiphy: CSIPHY device @@ -550,7 +559,7 @@ int msm_csiphy_subdev_init(struct camss *camss, { struct device *dev = camss->dev; struct platform_device *pdev = to_platform_device(dev); - int i, j; + int i, j, k; int ret; csiphy->camss = camss; @@ -666,19 +675,19 @@ int msm_csiphy_subdev_init(struct camss *camss, for (j = 0; j < clock->nfreqs; j++) clock->freq[j] = res->clock_rate[i][j]; - if (!strcmp(clock->name, "csiphy0_timer") || - !strcmp(clock->name, "csiphy1_timer") || - !strcmp(clock->name, "csiphy2_timer") || - !strcmp(clock->name, "csiphy3_timer") || - !strcmp(clock->name, "csiphy4_timer") || - !strcmp(clock->name, "csiphy5_timer")) - csiphy->rate_set[i] = true; - - if (camss->res->version == CAMSS_660 && - (!strcmp(clock->name, "csi0_phy") || - !strcmp(clock->name, "csi1_phy") || - !strcmp(clock->name, "csi2_phy"))) - csiphy->rate_set[i] = true; + for (k = 0; k < camss->res->csiphy_num; k++) { + csiphy->rate_set[i] = csiphy_match_clock_name(clock->name, + "csiphy%d_timer", k); + if (csiphy->rate_set[i]) + break; + + if (camss->res->version == CAMSS_660) { + csiphy->rate_set[i] = csiphy_match_clock_name(clock->name, + "csi%d_phy", k); + if (csiphy->rate_set[i]) + break; + } + } } return 0; -- 2.41.0