From mboxrd@z Thu Jan 1 00:00:00 1970 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 D8B91C433FE for ; Tue, 22 Nov 2022 13:03:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229750AbiKVNDp (ORCPT ); Tue, 22 Nov 2022 08:03:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbiKVNDp (ORCPT ); Tue, 22 Nov 2022 08:03:45 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E01C427DF2; Tue, 22 Nov 2022 05:03:43 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7DF9A616F5; Tue, 22 Nov 2022 13:03:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D185CC433C1; Tue, 22 Nov 2022 13:03:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669122222; bh=mgmJOslQRpubt6idGpmaC3UPQDoiukdDZmycvGkW9tE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=olhPl7ruPvtahdq4dZWXSPb/a6roHf9LKOlS5VoVGCsnp1KSIIWqz7o2tp/qxyWcU Xd1qXTdNVwTAtsdzPqVHL6y1wrY0YA2k4kztxeiFOc7IYACbfnMXn9pbLxZXTsHDnp XwUXOc0QEacL7tyAi7/ORVBReDlugf34I9Iw8NtM4a83yoUTqiVEUVObhuZ817U+vI jU2vHfEo180/e7xu84t4h9IBFvrQR0eX+Fefe+GuvAoQkZ761j8BRuiXXeULt8MJ7l 9il/5a1+NpL3F0HtoPNS/jU5dYo/vz5TxwDonS7Zrue5ln17W/9+Euv4YbxSJiEIRs 8E/R/TkuC3GPw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oxSw8-007rZX-3D; Tue, 22 Nov 2022 13:03:40 +0000 Date: Tue, 22 Nov 2022 13:03:39 +0000 Message-ID: <86pmdfnntg.wl-maz@kernel.org> From: Marc Zyngier To: AngeloGioacchino Del Regno Cc: tglx@linutronix.de, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, matthias.bgg@gmail.com, youlin.pei@mediatek.com, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: Re: [PATCH v1 3/4] irqchip: irq-mtk-cirq: Move register offsets to const array In-Reply-To: <20221118100639.33704-4-angelogioacchino.delregno@collabora.com> References: <20221118100639.33704-1-angelogioacchino.delregno@collabora.com> <20221118100639.33704-4-angelogioacchino.delregno@collabora.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: angelogioacchino.delregno@collabora.com, tglx@linutronix.de, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, matthias.bgg@gmail.com, youlin.pei@mediatek.com, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org On Fri, 18 Nov 2022 10:06:38 +0000, AngeloGioacchino Del Regno wrote: > > In preparation to add support for new SoCs having different register > offsets, add an enumeration that documents registers and move the > register offsets definitions to a u32 array. > > Of course, every usage of the definitions was changed to use the > newly introduced register offsets array. > > This change brings no functional changes. > > Signed-off-by: AngeloGioacchino Del Regno > --- > drivers/irqchip/irq-mtk-cirq.c | 62 ++++++++++++++++++++++++---------- > 1 file changed, 44 insertions(+), 18 deletions(-) > > diff --git a/drivers/irqchip/irq-mtk-cirq.c b/drivers/irqchip/irq-mtk-cirq.c > index 9bca0918078e..affbc0f48550 100644 > --- a/drivers/irqchip/irq-mtk-cirq.c > +++ b/drivers/irqchip/irq-mtk-cirq.c > @@ -15,14 +15,30 @@ > #include > #include > > -#define CIRQ_ACK 0x40 > -#define CIRQ_MASK_SET 0xc0 > -#define CIRQ_MASK_CLR 0x100 > -#define CIRQ_SENS_SET 0x180 > -#define CIRQ_SENS_CLR 0x1c0 > -#define CIRQ_POL_SET 0x240 > -#define CIRQ_POL_CLR 0x280 > -#define CIRQ_CONTROL 0x300 > +enum mtk_cirq_reg_index { > + CIRQ_STA = 0, Enums starting from 0 are the default. > + CIRQ_ACK, > + CIRQ_MASK_SET, > + CIRQ_MASK_CLR, > + CIRQ_SENS_SET, > + CIRQ_SENS_CLR, > + CIRQ_POL_SET, > + CIRQ_POL_CLR, > + CIRQ_CONTROL, > + CIRQ_MAX What's the use of this last constant? > +}; > + > +static const u32 mtk_cirq_regs_v1[] = { > + [CIRQ_STA] = 0x0, > + [CIRQ_ACK] = 0x40, > + [CIRQ_MASK_SET] = 0xc0, > + [CIRQ_MASK_CLR] = 0x100, > + [CIRQ_SENS_SET] = 0x180, > + [CIRQ_SENS_CLR] = 0x1c0, > + [CIRQ_POL_SET] = 0x240, > + [CIRQ_POL_CLR] = 0x280, > + [CIRQ_CONTROL] = 0x300, > +}; > > #define CIRQ_EN 0x1 > #define CIRQ_EDGE 0x2 > @@ -32,18 +48,20 @@ struct mtk_cirq_chip_data { > void __iomem *base; > unsigned int ext_irq_start; > unsigned int ext_irq_end; > + const u32 *regs; This is an array of *offsets*, not registers. Please name it accordingly. > struct irq_domain *domain; > }; > > static struct mtk_cirq_chip_data *cirq_data; > > -static void mtk_cirq_write_mask(struct irq_data *data, unsigned int offset) > +static void mtk_cirq_write_mask(struct irq_data *data, enum mtk_cirq_reg_index idx) > { > struct mtk_cirq_chip_data *chip_data = data->chip_data; > unsigned int cirq_num = data->hwirq; > u32 mask = 1 << (cirq_num % 32); > + u32 reg = chip_data->regs[idx] + (cirq_num / 32) * 4; Please provide an accessor that takes chip_data and an index, and returns an address. > > - writel_relaxed(mask, chip_data->base + offset + (cirq_num / 32) * 4); > + writel_relaxed(mask, chip_data->base + reg); > } > > static void mtk_cirq_mask(struct irq_data *data) > @@ -160,7 +178,7 @@ static const struct irq_domain_ops cirq_domain_ops = { > #ifdef CONFIG_PM_SLEEP > static int mtk_cirq_suspend(void) > { > - u32 value, mask; > + u32 value, mask, reg; > unsigned int irq, hwirq_num; > bool pending, masked; > int i, pendret, maskret; > @@ -200,31 +218,34 @@ static int mtk_cirq_suspend(void) > continue; > } > > + reg = cirq_data->regs[CIRQ_ACK] + (i / 32) * 4; > mask = 1 << (i % 32); > - writel_relaxed(mask, cirq_data->base + CIRQ_ACK + (i / 32) * 4); > + writel_relaxed(mask, cirq_data->base + reg); > } > > /* set edge_only mode, record edge-triggerd interrupts */ > /* enable cirq */ > - value = readl_relaxed(cirq_data->base + CIRQ_CONTROL); > + reg = cirq_data->regs[CIRQ_CONTROL]; > + value = readl_relaxed(cirq_data->base + reg); > value |= (CIRQ_EDGE | CIRQ_EN); > - writel_relaxed(value, cirq_data->base + CIRQ_CONTROL); > + writel_relaxed(value, cirq_data->base + reg); > > return 0; > } > > static void mtk_cirq_resume(void) > { > + u32 reg = cirq_data->regs[CIRQ_CONTROL]; > u32 value; > > /* flush recorded interrupts, will send signals to parent controller */ > - value = readl_relaxed(cirq_data->base + CIRQ_CONTROL); > - writel_relaxed(value | CIRQ_FLUSH, cirq_data->base + CIRQ_CONTROL); > + value = readl_relaxed(cirq_data->base + reg); > + writel_relaxed(value | CIRQ_FLUSH, cirq_data->base + reg); > > /* disable cirq */ > - value = readl_relaxed(cirq_data->base + CIRQ_CONTROL); > + value = readl_relaxed(cirq_data->base + reg); > value &= ~(CIRQ_EDGE | CIRQ_EN); > - writel_relaxed(value, cirq_data->base + CIRQ_CONTROL); > + writel_relaxed(value, cirq_data->base + reg); > } > > static struct syscore_ops mtk_cirq_syscore_ops = { > @@ -240,6 +261,9 @@ static void mtk_cirq_syscore_init(void) > static inline void mtk_cirq_syscore_init(void) {} > #endif > > +static const struct of_device_id mtk_cirq_of_match[] = { > + { .compatible = "mediatek, > + I can tell by this hunk the quality of testing this patch has received. > static int __init mtk_cirq_of_init(struct device_node *node, > struct device_node *parent) > { > @@ -274,6 +298,8 @@ static int __init mtk_cirq_of_init(struct device_node *node, > if (ret) > goto out_unmap; > > + cirq_data->regs = mtk_cirq_regs_v1; Why isn't this obtained from the matching array? > + > irq_num = cirq_data->ext_irq_end - cirq_data->ext_irq_start + 1; > domain = irq_domain_add_hierarchy(domain_parent, 0, > irq_num, node, M. -- Without deviation from the norm, progress is not possible.