[PATCH 1/6] interconnect: qcom: Move bcm_div() to common code
From: Konrad Dybcio
Date: Wed Sep 09 2026 - 15:12:32 EST
From: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>
This helper is useful for both SMD_RPM and RPMH code, extract it.
Assisted-by: LLM
Signed-off-by: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>
---
drivers/interconnect/qcom/bcm-voter.c | 21 +++++----------------
drivers/interconnect/qcom/icc-common.h | 9 +++++++++
2 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/drivers/interconnect/qcom/bcm-voter.c b/drivers/interconnect/qcom/bcm-voter.c
index a2d437a05a11..cdb0c5ee5cbc 100644
--- a/drivers/interconnect/qcom/bcm-voter.c
+++ b/drivers/interconnect/qcom/bcm-voter.c
@@ -3,7 +3,6 @@
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
*/
-#include <asm/div64.h>
#include <linux/interconnect-provider.h>
#include <linux/list_sort.h>
#include <linux/module.h>
@@ -14,6 +13,7 @@
#include <soc/qcom/tcs.h>
#include "bcm-voter.h"
+#include "icc-common.h"
#include "icc-rpmh.h"
static LIST_HEAD(bcm_voters);
@@ -47,17 +47,6 @@ static int cmp_vcd(void *priv, const struct list_head *a, const struct list_head
return bcm_a->aux_data.vcd - bcm_b->aux_data.vcd;
}
-static u64 bcm_div(u64 num, u32 base)
-{
- /* Ensure that small votes aren't lost. */
- if (num && num < base)
- return 1;
-
- do_div(num, base);
-
- return num;
-}
-
/* BCMs with enable_mask use one-hot-encoding for on/off signaling */
static void bcm_aggregate_mask(struct qcom_icc_bcm *bcm)
{
@@ -99,20 +88,20 @@ static void bcm_aggregate(struct qcom_icc_bcm *bcm)
for (bucket = 0; bucket < QCOM_ICC_NUM_BUCKETS; bucket++) {
for (i = 0; i < bcm->num_nodes; i++) {
node = bcm->nodes[i];
- temp = bcm_div(node->sum_avg[bucket] * bcm->aux_data.width,
+ temp = qcom_bw_div(node->sum_avg[bucket] * bcm->aux_data.width,
node->buswidth * node->channels);
agg_avg[bucket] = max(agg_avg[bucket], temp);
- temp = bcm_div(node->max_peak[bucket] * bcm->aux_data.width,
+ temp = qcom_bw_div(node->max_peak[bucket] * bcm->aux_data.width,
node->buswidth);
agg_peak[bucket] = max(agg_peak[bucket], temp);
}
temp = agg_avg[bucket] * bcm->vote_scale;
- bcm->vote_x[bucket] = bcm_div(temp, bcm->aux_data.unit);
+ bcm->vote_x[bucket] = qcom_bw_div(temp, bcm->aux_data.unit);
temp = agg_peak[bucket] * bcm->vote_scale;
- bcm->vote_y[bucket] = bcm_div(temp, bcm->aux_data.unit);
+ bcm->vote_y[bucket] = qcom_bw_div(temp, bcm->aux_data.unit);
}
if (bcm->keepalive && bcm->vote_x[QCOM_ICC_BUCKET_AMC] == 0 &&
diff --git a/drivers/interconnect/qcom/icc-common.h b/drivers/interconnect/qcom/icc-common.h
index 21c39b163948..af4b5a6f30b7 100644
--- a/drivers/interconnect/qcom/icc-common.h
+++ b/drivers/interconnect/qcom/icc-common.h
@@ -7,6 +7,15 @@
#define __DRIVERS_INTERCONNECT_QCOM_ICC_COMMON_H__
#include <linux/interconnect-provider.h>
+#include <linux/math64.h>
+
+static inline u64 qcom_bw_div(u64 num, u32 base)
+{
+ if (num && num < base)
+ return 1;
+
+ return div_u64(num, base);
+}
struct icc_node_data *qcom_icc_xlate_extended(const struct of_phandle_args *spec,
void *data);
--
2.55.0