From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95B41371878 for ; Sun, 21 Jun 2026 21:41:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782078093; cv=none; b=Gb+wdCcwE1cNJpnh0QxOylT3KzIpByYMeqhxQbxYPMsVVPeI3fY72UEOfUSlExmGS9hUtxJBgHuM8zkogPhxJQ3zJEGu7H9lYJRBoAV5f43grVu0np+0SykdgYj/zBOrTWuBczd2FH3H6uFx4Amj/NNeBHSwYKnR68I1nHpyW+4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782078093; c=relaxed/simple; bh=sQ1wAjFR9295YnMlB9Sz4W7s2bJ8gyMgINXaeA5IRQs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=geFBh8EcDoLWnIkqV0EOwz2jPFIKE+whe6HW1JjQCYKk3dHt2F7L0euaueTt9qFiLgXXJpq4sCLBIyJ2IbOXe4XmIPWXqEJPctxnZOMFu510q/g5WXBTt+25gmLrvXtneYKYOVQK7/kaS2t0D/ExdxEYlc8nTKIG0DgK90L9998= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KsFfVJy1; arc=none smtp.client-ip=209.85.219.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KsFfVJy1" Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-8dc87f7d68bso43494756d6.3 for ; Sun, 21 Jun 2026 14:41:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782078091; x=1782682891; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=XMh31ZzkY75rM1uCI6Py4J/7TBsM66ozEJNyE9b7Chg=; b=KsFfVJy1DpOeoigKY98IPPOXhnwfW0r5NnCs4CNfHw8DJfM8WS35k6SdHFElnbieaD x/ozn2YXulhv+aR0jlKYpXYZaMlXG3Xn4xdzWJGeu8Vt24vlF9QGR6pBizv7Yf//2NPG 6l2E8+vskx1QC4678+J7byeKlgPN2UF7AMBtjyn81UtgM4xfYBaUgsx+Wphx1X8N+ykU kwnqpBz9+a4ZLePXFkEpEH5zWZGapfGBByWDePxMBBITu8YJxcxSUIl2+M9SknlCUzch aGh6cwQeKtOAlzMrNhVUA74mTJb33opsBwVcs3fRDHWZWLgVRXLMOIYqW4Mb2V3iK4Wi kVyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782078091; x=1782682891; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=XMh31ZzkY75rM1uCI6Py4J/7TBsM66ozEJNyE9b7Chg=; b=ClC0nZhebveiAQOfdnIvrEhkHmNlmMFA6fZ8aZ6+68mDP9m7kOmsHhSnzHD9Rae2uq x5pu1p6AM/iA4hxRLgLuxU76Jdoh3FCWYzZ38Z0myOO7q27wtPMZZyGZ5rodRrzGjYLC IlgxI5CgixhNnEyT5+6bTUxLrVnh98i2MvdT+SF40mkO9YXWZqqHISw/KmuMxGNlABU3 DTp9cVh5payzfGlW7J3qYFhpxfJDZcViCnsdpNVMHR8d8gYFpzBb3etJrX5pP0MoaAv0 4ap2vjdDMedUDk1xg/+tps9s+x8kBF47L6opblXAVzJ91SpFDN+YArVlrhy4ft5fCuej Dwig== X-Forwarded-Encrypted: i=1; AHgh+RofF6ywbP0BFscLgrU5ouqzQGkTB1qHuJvh5Zew1663wFhJDRGz9LKJkVpn9Cko2JPOKA6DAtfwtzVazA0=@vger.kernel.org X-Gm-Message-State: AOJu0YwScD/hlowms3rN5s/+c+Khy8Ww4sq+PgWBR4SyR1FXkUUi/6AV HGnqYmV1g84EBDHHe9aSsq7d1LBG5YmXQ+iZ7QidZQ+G390N2+eaZ0ML X-Gm-Gg: AfdE7cnfYT9A9GY+NohjgTs58sO75FPoMk5W+MsUo58JFfsyLT9TFoK0NQoB6RwvooR nARDnnRKaKvOn75zZayTbMQgrz/kdJIdrY12nvTnEaTgeAP/27V065Lp1LCVh0hbzJtoK4ElC3y bklsr5dC/CzXdMyRQ0t6OYz0TbcILuGRtrEuu+aBRqu///H6Jx+rc1uUkskUWjLOVKd4M1LJn9D yKOCf0XNyT0FnUHyg5ENmp5UA43aBjYZfDvPcADkhL3+c8YFsp3uOFqhoizium3Pg6Fe1/wiuPA 0ka6aNRi26zSpwF9SL0FfnhV4hB3gwK7mIakFczS8G88io5ABXYu9ZihRePGyn38hSTjG7588iq dAGf0iqSV0I12mwttglGELOUd/WA2fvv0Cc9IJUzwvPaBzc7tX1U2iJ3i2ruTh6Uc3bS4WsR8BE zVQG14L+sJNRITJg== X-Received: by 2002:a05:6214:1bc6:b0:8cc:ed49:bdc9 with SMTP id 6a1803df08f44-8de3b43e008mr217413546d6.5.1782078090586; Sun, 21 Jun 2026 14:41:30 -0700 (PDT) Received: from [172.17.0.2] ([138.28.231.64]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8df81cde9ecsm76274676d6.24.2026.06.21.14.41.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jun 2026 14:41:30 -0700 (PDT) From: Yuanshen Cao Date: Sun, 21 Jun 2026 21:40:54 +0000 Subject: [PATCH v2 1/5] dmaengine: sun6i-dma: Refactor to support A733 interrupt and register handling Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260621-sun60i-a733-dma-v2-1-340f205891cc@gmail.com> References: <20260621-sun60i-a733-dma-v2-0-340f205891cc@gmail.com> In-Reply-To: <20260621-sun60i-a733-dma-v2-0-340f205891cc@gmail.com> To: Vinod Koul , Frank Li , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Maxime Ripard Cc: Yuanshen Cao , dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org X-Mailer: b4 0.15.2 Refactor to support the Allwinner A733 DMA controller. Currently, the `sun6i-dma` driver has several functions related to interrupt handling (reading/writing interrupt enable and status registers) and register dumping that are hardcoded. To support the A733, which has different register layouts and interrupt handling logic, these functions are being moved into the `sun6i_dma_config` structure as function pointers. This allows the driver to use a polymorphic approach where the specific implementation is determined by the hardware configuration assigned during device probing. Changes: - Added function pointers to `struct sun6i_dma_config` for: - `dump_com_regs` - `read_irq_en` - `write_irq_en` - `read_irq_stat` - `write_irq_stat` - Implemented generic `sun6i_read/write_irq_*` functions for existing hardware. - Added a macro and updated existing `sun6i_dma_config` instances (A31, A23, H3, A64, A100, H6, V3S) to use these new function pointers. Signed-off-by: Yuanshen Cao --- drivers/dma/sun6i-dma.c | 50 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c index a9a254dbf8cb..ef3052c4ab36 100644 --- a/drivers/dma/sun6i-dma.c +++ b/drivers/dma/sun6i-dma.c @@ -138,6 +138,11 @@ struct sun6i_dma_config { void (*set_burst_length)(u32 *p_cfg, s8 src_burst, s8 dst_burst); void (*set_drq)(u32 *p_cfg, s8 src_drq, s8 dst_drq); void (*set_mode)(u32 *p_cfg, s8 src_mode, s8 dst_mode); + void (*dump_com_regs)(struct sun6i_dma_dev *sdev); + u32 (*read_irq_en)(struct sun6i_dma_dev *sdev, u32 irq_reg); + void (*write_irq_en)(struct sun6i_dma_dev *sdev, u32 irq_reg, u32 irq_val); + u32 (*read_irq_stat)(struct sun6i_dma_dev *sdev, u32 irq_reg); + void (*write_irq_stat)(struct sun6i_dma_dev *sdev, u32 irq_reg, u32 status); u32 src_burst_lengths; u32 dst_burst_lengths; u32 src_addr_widths; @@ -347,6 +352,26 @@ static void sun6i_set_mode_h6(u32 *p_cfg, s8 src_mode, s8 dst_mode) DMA_CHAN_CFG_DST_MODE_H6(dst_mode); } +static u32 sun6i_read_irq_en(struct sun6i_dma_dev *sdev, u32 irq_reg) +{ + return readl(sdev->base + DMA_IRQ_EN(irq_reg)); +} + +static void sun6i_write_irq_en(struct sun6i_dma_dev *sdev, u32 irq_reg, u32 irq_val) +{ + writel(irq_val, sdev->base + DMA_IRQ_EN(irq_reg)); +} + +static u32 sun6i_read_irq_stat(struct sun6i_dma_dev *sdev, u32 irq_reg) +{ + return readl(sdev->base + DMA_IRQ_STAT(irq_reg)); +} + +static void sun6i_write_irq_stat(struct sun6i_dma_dev *sdev, u32 irq_reg, u32 status) +{ + writel(status, sdev->base + DMA_IRQ_STAT(irq_reg)); +} + static size_t sun6i_get_chan_size(struct sun6i_pchan *pchan) { struct sun6i_desc *txd = pchan->desc; @@ -460,16 +485,16 @@ static int sun6i_dma_start_desc(struct sun6i_vchan *vchan) vchan->irq_type = vchan->cyclic ? DMA_IRQ_PKG : DMA_IRQ_QUEUE; - irq_val = readl(sdev->base + DMA_IRQ_EN(irq_reg)); + irq_val = sdev->cfg->read_irq_en(sdev, irq_reg); irq_val &= ~((DMA_IRQ_HALF | DMA_IRQ_PKG | DMA_IRQ_QUEUE) << (irq_offset * DMA_IRQ_CHAN_WIDTH)); irq_val |= vchan->irq_type << (irq_offset * DMA_IRQ_CHAN_WIDTH); - writel(irq_val, sdev->base + DMA_IRQ_EN(irq_reg)); + sdev->cfg->write_irq_en(sdev, irq_reg, irq_val); writel(pchan->desc->p_lli, pchan->base + DMA_CHAN_LLI_ADDR); writel(DMA_CHAN_ENABLE_START, pchan->base + DMA_CHAN_ENABLE); - sun6i_dma_dump_com_regs(sdev); + sdev->cfg->dump_com_regs(sdev); sun6i_dma_dump_chan_regs(sdev, pchan); return 0; @@ -549,14 +574,14 @@ static irqreturn_t sun6i_dma_interrupt(int irq, void *dev_id) u32 status; for (i = 0; i < sdev->num_pchans / DMA_IRQ_CHAN_NR; i++) { - status = readl(sdev->base + DMA_IRQ_STAT(i)); + status = sdev->cfg->read_irq_stat(sdev, i); if (!status) continue; dev_dbg(sdev->slave.dev, "DMA irq status %s: 0x%x\n", str_high_low(i), status); - writel(status, sdev->base + DMA_IRQ_STAT(i)); + sdev->cfg->write_irq_stat(sdev, i, status); for (j = 0; (j < DMA_IRQ_CHAN_NR) && status; j++) { pchan = sdev->pchans + j; @@ -1101,6 +1126,13 @@ static inline void sun6i_dma_free(struct sun6i_dma_dev *sdev) } } +#define SUN6I_DMA_IRQ_A31_COMMON_OPS \ + .dump_com_regs = sun6i_dma_dump_com_regs, \ + .read_irq_en = sun6i_read_irq_en, \ + .write_irq_en = sun6i_write_irq_en, \ + .read_irq_stat = sun6i_read_irq_stat, \ + .write_irq_stat = sun6i_write_irq_stat, + /* * For A31: * @@ -1132,6 +1164,7 @@ static struct sun6i_dma_config sun6i_a31_dma_cfg = { .dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | BIT(DMA_SLAVE_BUSWIDTH_4_BYTES), + SUN6I_DMA_IRQ_A31_COMMON_OPS }; /* @@ -1155,6 +1188,7 @@ static struct sun6i_dma_config sun8i_a23_dma_cfg = { .dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | BIT(DMA_SLAVE_BUSWIDTH_4_BYTES), + SUN6I_DMA_IRQ_A31_COMMON_OPS }; static struct sun6i_dma_config sun8i_a83t_dma_cfg = { @@ -1173,6 +1207,7 @@ static struct sun6i_dma_config sun8i_a83t_dma_cfg = { .dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | BIT(DMA_SLAVE_BUSWIDTH_4_BYTES), + SUN6I_DMA_IRQ_A31_COMMON_OPS }; /* @@ -1200,6 +1235,7 @@ static struct sun6i_dma_config sun8i_h3_dma_cfg = { BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) | BIT(DMA_SLAVE_BUSWIDTH_8_BYTES), + SUN6I_DMA_IRQ_A31_COMMON_OPS }; /* @@ -1221,6 +1257,7 @@ static struct sun6i_dma_config sun50i_a64_dma_cfg = { BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) | BIT(DMA_SLAVE_BUSWIDTH_8_BYTES), + SUN6I_DMA_IRQ_A31_COMMON_OPS }; /* @@ -1244,6 +1281,7 @@ static struct sun6i_dma_config sun50i_a100_dma_cfg = { BIT(DMA_SLAVE_BUSWIDTH_8_BYTES), .has_high_addr = true, .has_mbus_clk = true, + SUN6I_DMA_IRQ_A31_COMMON_OPS }; /* @@ -1266,6 +1304,7 @@ static struct sun6i_dma_config sun50i_h6_dma_cfg = { BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) | BIT(DMA_SLAVE_BUSWIDTH_8_BYTES), .has_mbus_clk = true, + SUN6I_DMA_IRQ_A31_COMMON_OPS }; /* @@ -1289,6 +1328,7 @@ static struct sun6i_dma_config sun8i_v3s_dma_cfg = { .dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | BIT(DMA_SLAVE_BUSWIDTH_4_BYTES), + SUN6I_DMA_IRQ_A31_COMMON_OPS }; static const struct of_device_id sun6i_dma_match[] = { -- 2.54.0