[PATCH v2 06/17] dmaengine: ti: k3-udma: Add variant-specific function pointers to udma_dev

Sai Sree Kartheek Adivi
2025-06-12T07:31:01Z

Introduce function pointers in the udma_dev structure to allow
variant-specific implementations for certain operations.
This prepares the driver for supporting multiple K3 UDMA variants,
such as UDMA v2, with minimal code duplication.

No functional changes intended in this commit.

Signed-off-by: Sai Sree Kartheek Adivi <s-adivi@ti.com>
---
drivers/dma/ti/k3-udma.c | 38 ++++++++++++++++++++++----------------
drivers/dma/ti/k3-udma.h | 5 +++++
2 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c
index efbd16dc3f931..db342682edb23 100644
--- a/drivers/dma/ti/k3-udma.c
+++ b/drivers/dma/ti/k3-udma.c
@@ -329,7 +329,7 @@ static int udma_start(struct udma_chan *uc)
}

/* Make sure that we clear the teardown bit, if it is set */
- udma_reset_chan(uc, false);
+ uc->ud->reset_chan(uc, false);

/* Push descriptors before we start the channel */
udma_start_desc(uc);
@@ -521,8 +521,8 @@ static void udma_check_tx_completion(struct work_struct *work)
if (uc->desc) {
struct udma_desc *d = uc->desc;

- udma_decrement_byte_counters(uc, d->residue);
- udma_start(uc);
+ uc->ud->decrement_byte_counters(uc, d->residue);
+ uc->ud->start(uc);
vchan_cookie_complete(&d->vd);
break;
}
@@ -554,7 +554,7 @@ static irqreturn_t udma_ring_irq_handler(int irq, void *data)
}

if (!uc->desc)
- udma_start(uc);
+ uc->ud->start(uc);

goto out;
}
@@ -576,8 +576,8 @@ static irqreturn_t udma_ring_irq_handler(int irq, void *data)
vchan_cyclic_callback(&d->vd);
} else {
if (udma_is_desc_really_done(uc, d)) {
- udma_decrement_byte_counters(uc, d->residue);
- udma_start(uc);
+ uc->ud->decrement_byte_counters(uc, d->residue);
+ uc->ud->start(uc);
vchan_cookie_complete(&d->vd);
} else {
schedule_delayed_work(&uc->tx_drain.work,
@@ -612,8 +612,8 @@ static irqreturn_t udma_udma_irq_handler(int irq, void *data)
vchan_cyclic_callback(&d->vd);
} else {
/* TODO: figure out the real amount of data */
- udma_decrement_byte_counters(uc, d->residue);
- udma_start(uc);
+ uc->ud->decrement_byte_counters(uc, d->residue);
+ uc->ud->start(uc);
vchan_cookie_complete(&d->vd);
}
}
@@ -1654,7 +1654,7 @@ static int udma_alloc_chan_resources(struct dma_chan *chan)

if (udma_is_chan_running(uc)) {
dev_warn(ud->dev, "chan%d: is running!\n", uc->id);
- udma_reset_chan(uc, false);
+ ud->reset_chan(uc, false);
if (udma_is_chan_running(uc)) {
dev_err(ud->dev, "chan%d: won't stop!\n", uc->id);
ret = -EBUSY;
@@ -1821,7 +1821,7 @@ static int bcdma_alloc_chan_resources(struct dma_chan *chan)

if (udma_is_chan_running(uc)) {
dev_warn(ud->dev, "chan%d: is running!\n", uc->id);
- udma_reset_chan(uc, false);
+ ud->reset_chan(uc, false);
if (udma_is_chan_running(uc)) {
dev_err(ud->dev, "chan%d: won't stop!\n", uc->id);
ret = -EBUSY;
@@ -2014,7 +2014,7 @@ static int pktdma_alloc_chan_resources(struct dma_chan *chan)

if (udma_is_chan_running(uc)) {
dev_warn(ud->dev, "chan%d: is running!\n", uc->id);
- udma_reset_chan(uc, false);
+ ud->reset_chan(uc, false);
if (udma_is_chan_running(uc)) {
dev_err(ud->dev, "chan%d: won't stop!\n", uc->id);
ret = -EBUSY;
@@ -2123,7 +2123,7 @@ static void udma_issue_pending(struct dma_chan *chan)
*/
if (!(uc->state == UDMA_CHAN_IS_TERMINATING &&
udma_is_chan_running(uc)))
- udma_start(uc);
+ uc->ud->start(uc);
}

spin_unlock_irqrestore(&uc->vc.lock, flags);
@@ -2265,7 +2265,7 @@ static int udma_terminate_all(struct dma_chan *chan)
spin_lock_irqsave(&uc->vc.lock, flags);

if (udma_is_chan_running(uc))
- udma_stop(uc);
+ uc->ud->stop(uc);

if (uc->desc) {
uc->terminated_desc = uc->desc;
@@ -2297,11 +2297,11 @@ static void udma_synchronize(struct dma_chan *chan)
dev_warn(uc->ud->dev, "chan%d teardown timeout!\n",
uc->id);
udma_dump_chan_stdata(uc);
- udma_reset_chan(uc, true);
+ uc->ud->reset_chan(uc, true);
}
}

- udma_reset_chan(uc, false);
+ uc->ud->reset_chan(uc, false);
if (udma_is_chan_running(uc))
dev_warn(uc->ud->dev, "chan%d refused to stop!\n", uc->id);

@@ -2355,7 +2355,7 @@ static void udma_free_chan_resources(struct dma_chan *chan)

udma_terminate_all(chan);
if (uc->terminated_desc) {
- udma_reset_chan(uc, false);
+ ud->reset_chan(uc, false);
udma_reset_rings(uc);
}

@@ -3694,6 +3694,12 @@ static int udma_probe(struct platform_device *pdev)
ud->soc_data = soc->data;
}

+ // Setup function pointers
+ ud->start = udma_start;
+ ud->stop = udma_stop;
+ ud->reset_chan = udma_reset_chan;
+ ud->decrement_byte_counters = udma_decrement_byte_counters;
+
ret = udma_get_mmrs(pdev, ud);
if (ret)
return ret;
diff --git a/drivers/dma/ti/k3-udma.h b/drivers/dma/ti/k3-udma.h
index edff919b8b347..67425ed1273aa 100644
--- a/drivers/dma/ti/k3-udma.h
+++ b/drivers/dma/ti/k3-udma.h
@@ -343,6 +343,11 @@ struct udma_dev {
u32 psil_base;
u32 atype;
u32 asel;
+
+ int (*start)(struct udma_chan *uc);
+ int (*stop)(struct udma_chan *uc);
+ int (*reset_chan)(struct udma_chan *uc, bool hard);
+ void (*decrement_byte_counters)(struct udma_chan *uc, u32 val);
};

struct udma_desc {
--
2.34.1