Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3599850rdg; Tue, 17 Oct 2023 23:19:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxjpneJciIiGkn45NPJkoKxMDxq1CIxo4pJx57TNStohH6bM7L5cG78NjmgCe37ZL3IiO5 X-Received: by 2002:a05:6830:1d5:b0:6c4:a30c:f3f1 with SMTP id r21-20020a05683001d500b006c4a30cf3f1mr4344293ota.19.1697609946623; Tue, 17 Oct 2023 23:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697609946; cv=none; d=google.com; s=arc-20160816; b=ozEYi7MmYz4GhYld6YsUsZY5c8hTqZALRmAnEWiIQjPiZkUJt92dYMm1q+PKbxdiK1 HLJmSJIhImCOsWpekRk2CiEakVslER5zSupnigvIZJtk+ggJfcbX8Fh/bS6STicL3s6g LKFX/8umZF3QZ+hMwPnJcuYvB/iH3fdX9DhsS91Wh5fpUPd/dEodobCvzGWS7aM2ktHC RNyyYdDHlgzOA0AUmkr1gA+Rlh3q22svTrYN1XK7t0Py7kTo+pCJHKvo1VObIJXMBg7M GEatqXN+v7RSkAwNTZrAlVFK1bm2ausF5wlqs/oxVPADJDilhp/vStmZOTrkzMYhuqJc TZ1A== 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; bh=wFqAtGjEvCicHT0s3lqohL/GXN43uV2DMMR+JQPIDw0=; fh=fCKtpw9CfdQ3PvVD3VDWQjIZjGoF8tkGHyUGDo9ja4M=; b=pS496YT2CU9JwXO0QaqvIL+uwF5/85c0uMaPg/vFLmf2T4eY7tBtGk+OwoJjyiwlGo pbe/Wab6D9lirAJY1ZvvYFt8pzjGonYxbhi0cY1JNqVPpCGBPQQqmQc5olbNx1j7l9Y7 GY786kKTTC2i9bDsV/1D7YRpTPczVnDS/xNOU9VU4cKbFxp+EDpn/qzk0EwHCRKawScq zSBZd20pdLopzQ87b66Z7vKWvQC6U4Dt9bZi6/zOZZRGwOtVday4ERY8S+686kz8jFuN BOuitwC6yvFcSAgYudOGY3orw1uKTbzOnTOZAwyUyEvHsnrcqMfiL1Kv3BL2733uZxMb r4Ew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id i10-20020a63d44a000000b00577616e3ad9si1498310pgj.871.2023.10.17.23.19.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 23:19:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id A17C080268F6; Tue, 17 Oct 2023 23:18:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229685AbjJRGSb (ORCPT + 99 others); Wed, 18 Oct 2023 02:18:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344490AbjJRGRu (ORCPT ); Wed, 18 Oct 2023 02:17:50 -0400 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55BFD11D for ; Tue, 17 Oct 2023 23:17:48 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qszrx-0001Zp-7b; Wed, 18 Oct 2023 08:17:25 +0200 Received: from [2a0a:edc0:0:1101:1d::28] (helo=dude02.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qszrq-002UY3-Qg; Wed, 18 Oct 2023 08:17:18 +0200 Received: from sha by dude02.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1qszrq-00EviL-2J; Wed, 18 Oct 2023 08:17:18 +0200 From: Sascha Hauer To: linux-rockchip@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Heiko Stuebner , Chanwoo Choi , Kyungmin Park , MyungJoo Ham , Will Deacon , Mark Rutland , kernel@pengutronix.de, Michael Riesch , Robin Murphy , Vincent Legoll , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, Sebastian Reichel , Sascha Hauer Subject: [PATCH v8 07/26] PM / devfreq: rockchip-dfi: introduce channel mask Date: Wed, 18 Oct 2023 08:16:55 +0200 Message-Id: <20231018061714.3553817-8-s.hauer@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231018061714.3553817-1-s.hauer@pengutronix.de> References: <20231018061714.3553817-1-s.hauer@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 pete.vger.email 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 (pete.vger.email [0.0.0.0]); Tue, 17 Oct 2023 23:18:57 -0700 (PDT) Different Rockchip SoC variants have a different number of channels. Introduce a channel mask to make the number of channels configurable from SoC initialization code. Reviewed-by: Sebastian Reichel Signed-off-by: Sascha Hauer --- Notes: Changes since v7: - Loop only over channels present on a SoC drivers/devfreq/event/rockchip-dfi.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/devfreq/event/rockchip-dfi.c b/drivers/devfreq/event/rockchip-dfi.c index 126bb744645b6..28c18bbf6baa5 100644 --- a/drivers/devfreq/event/rockchip-dfi.c +++ b/drivers/devfreq/event/rockchip-dfi.c @@ -18,10 +18,11 @@ #include #include #include +#include #include -#define RK3399_DMC_NUM_CH 2 +#define DMC_MAX_CHANNELS 2 /* DDRMON_CTRL */ #define DDRMON_CTRL 0x04 @@ -44,7 +45,7 @@ struct dmc_count_channel { }; struct dmc_count { - struct dmc_count_channel c[RK3399_DMC_NUM_CH]; + struct dmc_count_channel c[DMC_MAX_CHANNELS]; }; /* @@ -61,6 +62,8 @@ struct rockchip_dfi { struct regmap *regmap_pmu; struct clk *clk; u32 ddr_type; + unsigned int channel_mask; + unsigned int max_channels; }; static void rockchip_dfi_start_hardware_counter(struct devfreq_event_dev *edev) @@ -95,7 +98,9 @@ static void rockchip_dfi_read_counters(struct devfreq_event_dev *edev, struct dm u32 i; void __iomem *dfi_regs = dfi->regs; - for (i = 0; i < RK3399_DMC_NUM_CH; i++) { + for (i = 0; i < dfi->max_channels; i++) { + if (!(dfi->channel_mask & BIT(i))) + continue; count->c[i].access = readl_relaxed(dfi_regs + DDRMON_CH0_DFI_ACCESS_NUM + i * 20); count->c[i].total = readl_relaxed(dfi_regs + @@ -145,9 +150,14 @@ static int rockchip_dfi_get_event(struct devfreq_event_dev *edev, rockchip_dfi_read_counters(edev, &count); /* We can only report one channel, so find the busiest one */ - for (i = 0; i < RK3399_DMC_NUM_CH; i++) { - u32 a = count.c[i].access - last->c[i].access; - u32 t = count.c[i].total - last->c[i].total; + for (i = 0; i < dfi->max_channels; i++) { + u32 a, t; + + if (!(dfi->channel_mask & BIT(i))) + continue; + + a = count.c[i].access - last->c[i].access; + t = count.c[i].total - last->c[i].total; if (a > access) { access = a; @@ -185,6 +195,9 @@ static int rk3399_dfi_init(struct rockchip_dfi *dfi) dfi->ddr_type = (val >> RK3399_PMUGRF_DDRTYPE_SHIFT) & RK3399_PMUGRF_DDRTYPE_MASK; + dfi->channel_mask = GENMASK(1, 0); + dfi->max_channels = 2; + return 0; }; -- 2.39.2