From patchwork Wed Aug 23 10:44:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 716352 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 E3BE1EE49B2 for ; Wed, 23 Aug 2023 10:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234103AbjHWKp3 (ORCPT ); Wed, 23 Aug 2023 06:45:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234062AbjHWKpM (ORCPT ); Wed, 23 Aug 2023 06:45:12 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E59B9CD9 for ; Wed, 23 Aug 2023 03:45:04 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3fee17aebc8so39541205e9.0 for ; Wed, 23 Aug 2023 03:45:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692787503; x=1693392303; 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=mhAJonHk82O1JU38yvxq//f+PgwfunLi3MPyMMxfsOJEb0ZCqmh5XBUy/1UdB0f74l cHECz8xH1UvCOEDmrCPDR1+4j+6Dv8cGzofbVMulHAL/aDchojUGnS2wGv60ewN6ao/o D19WNIpawZ8kRgsVpnchBH60LMuZB1MW8kRiWMbZVtC6miQVYEOlbl5SCA5FwwXuSc+x U1c71nCjLDWMoq5qTHSih++bHWPpzAQPba22VtPTSwIBljwVmstxDXWcd2Unh+vGb33E Llag17Zk3cCGLA+LDB94GZw/3kbkEEs/wAEOMqnPYOpWhfGYPPNRK66r+hOPwso9/CmO uIpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692787503; x=1693392303; 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=b9tT/nn1ZKuecOwykQ/qFguVlMkiopVZ3pvyijqmeBALAQ2F10F9lNQ0U3AMn5Akmj QmpEf2xM84poVA7ibHvoQhJ8XyWoe3A6Hr2OtmIIH97pQswDzGWF0U+CLJh9O5i66mQo XbA5s0ffBRNMy+FHMNT9rZRBG3AcM9LWkWeqy4gVnW4fRVaCkFXANajdg1EDqIEWG0EG 2SWxjzGdHH6X2Dy6rePnMFGecpnYCRuLQshzzjQ1B3q3gv1o5sYxPo4RBfozGqnDQlLB kNKfD0ydc2pBwO6YCIcK7Eqgfnif4G+OO41qHoxYhyeZh6Yudq5DAudZEE7A3UD/ciCn VmlQ== X-Gm-Message-State: AOJu0Yx4Rs/FJo8kKM1D7Tbt6XY3pfaP1OaEzrde5uKWKOc96XcpDgyK uv2rRPQw2nQKCfSpANqdF2gbVg== X-Google-Smtp-Source: AGHT+IG1+cvmYpNpk1eoo0KqVXeZN1HIsBfKTqiNgbwKTKafOvOkJR+Y/fxPgNluXdx8pZ5tnLXVHg== X-Received: by 2002:a5d:4fc7:0:b0:314:1b36:f440 with SMTP id h7-20020a5d4fc7000000b003141b36f440mr8428218wrw.70.1692787503323; Wed, 23 Aug 2023 03:45:03 -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 n4-20020a5d4204000000b0031c5dda3aedsm6281213wrq.95.2023.08.23.03.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 03:45:02 -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 v3 11/15] media: qcom: camss: Functionally decompose CSIPHY clock lookups Date: Wed, 23 Aug 2023 11:44:40 +0100 Message-ID: <20230823104444.1954663-12-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230823104444.1954663-1-bryan.odonoghue@linaro.org> References: <20230823104444.1954663-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@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;