Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp394299rdb; Fri, 17 Nov 2023 01:42:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGTRclO5kuRrPzbqyCbz4TnpVFwmPPGrOF0zJtLaxWOt63Zb3nr+KNzYtrh68zpQH90j8wR X-Received: by 2002:a05:6a20:3d09:b0:187:9521:92b9 with SMTP id y9-20020a056a203d0900b00187952192b9mr6546137pzi.53.1700214174900; Fri, 17 Nov 2023 01:42:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700214174; cv=none; d=google.com; s=arc-20160816; b=NSC/oFU34zo9KY0SRGNBgM1YUeXJDHFczp/3wqVED6FptiXIngxj9VwJ3HvHYzPlZH YppGlNIKOgx11JpKEiGmz1hT3tErLN7uM7azSEaIPK+cJaN67IfFAqiCIHfDK38pdF7p Z5oYILZNk4/ieRpI8M5i4PodX2MK4cYunVPBBPMW6fNncz8o2wjBa8y74JYWLX+hHgfK 6fziswPgk3GYnULM2gtRhv7be1sPq/FeKiQoJPoQ5x3HZDt+wKtm3MZY1AwLXJni+Kp6 hKz7PEsGMq5wS//lYVaP0I5/XSacExYU2LExiK7jRWFG+dnW97IvoaI0ZRDMaAODvUx6 z22A== 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=sP44+g1bH/qOSRtOIwRMmcTWlqOFMISlukISmRUTZhQ=; fh=m5p6pcg3y47Sg5VKYWXj0f0nOzgFq4l5+GGYwGce+t4=; b=Wly0yjd8/+EOSZK7riuptdZmtRbA1UnhUTh4bT59zWPwuhrhly077u/iXFLpEpcxKB 8WxJB5T80FW84xrrFHSeIcUgmgPw1O1Y09UDnz9GPNOw0cXmz9+J0iLBiqI7DyafzdAj Ldi1OPsU3t0ugw2ZN4jqk2NiD+22TKLm7fQ71V9Cm7mBjqICxf6kW4dgxauwOoY3V5jh BSb9ak5Og6ZjbykpafLkpCIHRPcq+eFyVS5JG5s1BTpkWSelXxaYiXDDasnlqAfozGl7 hR7woJDxHcmqCdWIjIm7FMUI8Br1cdxPXHAFVjdXqcqFoSjasZZHhOLxxPgUvibin0CH 6wTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=UfywWfto; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id h2-20020a170902f54200b001ce16042055si1523029plf.505.2023.11.17.01.42.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 01:42:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=UfywWfto; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 34A3A825D108; Fri, 17 Nov 2023 01:42:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345774AbjKQJmt (ORCPT + 99 others); Fri, 17 Nov 2023 04:42:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345747AbjKQJmn (ORCPT ); Fri, 17 Nov 2023 04:42:43 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9A8FB7; Fri, 17 Nov 2023 01:42:39 -0800 (PST) Received: from IcarusMOD.eternityproject.eu (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id EB9596607394; Fri, 17 Nov 2023 09:42:37 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1700214158; bh=lCOeXkBHj3GxnYKp57VPx13B7VONqu2PAmr9JmQp0B4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UfywWftonIYwMcfUYDS1omJB0srqfuS56s9ojBC835cHmRmQY/REA9kfrhEuAnmHP AJbqe0hCsLoGngT5ZIB+9sO8ARoh8Ic4z8mgghA29mHFHCz4LjGSvBCdXbhUqifnOl jJtFAWH7mcMEaU43eHd8oRGIsyGHlnA3h7vek8H7nO0GV5avA3Qz6CbhwfcQAPI4SW hf8y6LOAag5gndlwF5M+YE2YYVtnypLWW6NnzqjfkqzHgqEaafAtR7MPKpEUyy1eVx iMmwaIen0pxKpN8y7HOzjD5Ov5YQ9FWyHBk+XJYcfqDEqiCJlTz+eh3GvWJTlyK5s9 ywIUZiUtKK1cQ== From: AngeloGioacchino Del Regno To: matthias.bgg@gmail.com Cc: krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, robh+dt@kernel.org, angelogioacchino.delregno@collabora.com, p.zabel@pengutronix.de, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel@collabora.com, wenst@chromium.org Subject: [PATCH v1 04/20] soc: mediatek: mtk-svs: Build bank name string dynamically Date: Fri, 17 Nov 2023 10:42:12 +0100 Message-ID: <20231117094228.40013-5-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117094228.40013-1-angelogioacchino.delregno@collabora.com> References: <20231117094228.40013-1-angelogioacchino.delregno@collabora.com> 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_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 17 Nov 2023 01:42:53 -0800 (PST) In svs_bank_resource_setup() there is a "big" switch assigning different names depending on sw_id and type and this will surely grow: for example MT8186 has got a two-line type (high/low) SVS bank for CPU_BIG, and this would require more switch nesting. Simplify all of this by changing that to a devm_kasprintf() call that will concatenate the SW_ID string (e.g. SVSB_CPU_LITTLE) with the Type string (e.g. _LOW), resulting in the expected full bank name (e.g. SVSB_CPU_LITTLE_LOW). This being a dynamic allocation can be slower, but this happens only once in the life of this driver and it's not a performance path, so it's totally acceptable. Signed-off-by: AngeloGioacchino Del Regno --- drivers/soc/mediatek/mtk-svs.c | 39 +++++++++++++++------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/drivers/soc/mediatek/mtk-svs.c b/drivers/soc/mediatek/mtk-svs.c index ddbb9ba3e47d..1c7592fd6ae7 100644 --- a/drivers/soc/mediatek/mtk-svs.c +++ b/drivers/soc/mediatek/mtk-svs.c @@ -332,6 +332,14 @@ static const u32 svs_regs_v2[] = { [THSLPEVEB] = 0x330, }; +static const char * const svs_swid_names[SVSB_SWID_MAX] = { + "SVSB_CPU_LITTLE", "SVSB_CPU_BIG", "SVSB_CCI", "SVSB_GPU" +}; + +static const char * const svs_type_names[SVSB_TYPE_MAX] = { + "", "_LOW", "_HIGH" +}; + /** * struct svs_platform - svs platform control * @base: svs platform register base @@ -1696,34 +1704,21 @@ static int svs_bank_resource_setup(struct svs_platform *svsp) for (idx = 0; idx < svsp->bank_max; idx++) { svsb = &svsp->banks[idx]; - switch (svsb->sw_id) { - case SVSB_SWID_CPU_LITTLE: - svsb->name = "SVSB_CPU_LITTLE"; - break; - case SVSB_SWID_CPU_BIG: - svsb->name = "SVSB_CPU_BIG"; - break; - case SVSB_SWID_CCI: - svsb->name = "SVSB_CCI"; - break; - case SVSB_SWID_GPU: - if (svsb->type == SVSB_TYPE_HIGH) - svsb->name = "SVSB_GPU_HIGH"; - else if (svsb->type == SVSB_TYPE_LOW) - svsb->name = "SVSB_GPU_LOW"; - else - svsb->name = "SVSB_GPU"; - break; - default: - dev_err(svsb->dev, "unknown sw_id: %u\n", svsb->sw_id); + if (svsb->sw_id >= SVSB_SWID_MAX || svsb->type >= SVSB_TYPE_MAX) { + dev_err(svsb->dev, "unknown bank sw_id or type\n"); return -EINVAL; } - svsb->dev = devm_kzalloc(svsp->dev, sizeof(*svsb->dev), - GFP_KERNEL); + svsb->dev = devm_kzalloc(svsp->dev, sizeof(*svsb->dev), GFP_KERNEL); if (!svsb->dev) return -ENOMEM; + svsb->name = devm_kasprintf(svsp->dev, GFP_KERNEL, "%s%s", + svs_swid_names[svsb->sw_id], + svs_type_names[svsb->type]); + if (!svsb->name) + return -ENOMEM; + ret = dev_set_name(svsb->dev, "%s", svsb->name); if (ret) return ret; -- 2.42.0